confdb.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. /*
  2. * Copyright (c) 2008-2010 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_OBJECT_CREATE_CALLBACK:
  297. if (callbacks.confdb_object_create_change_notify_fn == NULL) {
  298. break;
  299. }
  300. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)dispatch_data;
  301. callbacks.confdb_object_create_change_notify_fn(handle,
  302. res_object_created_pt->object_handle,
  303. res_object_created_pt->parent_object_handle,
  304. res_object_created_pt->name.value,
  305. res_object_created_pt->name.length);
  306. break;
  307. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  308. if (callbacks.confdb_object_delete_change_notify_fn == NULL) {
  309. break;
  310. }
  311. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)dispatch_data;
  312. callbacks.confdb_object_delete_change_notify_fn(handle,
  313. res_object_destroyed_pt->parent_object_handle,
  314. res_object_destroyed_pt->name.value,
  315. res_object_destroyed_pt->name.length);
  316. break;
  317. case MESSAGE_RES_CONFDB_RELOAD_CALLBACK:
  318. if (callbacks.confdb_reload_notify_fn == NULL) {
  319. break;
  320. }
  321. res_reload_pt = (struct res_lib_confdb_reload_callback *)dispatch_data;
  322. callbacks.confdb_reload_notify_fn(handle,
  323. res_reload_pt->type);
  324. break;
  325. default:
  326. coroipcc_dispatch_put (confdb_inst->handle);
  327. error = CS_ERR_LIBRARY;
  328. goto error_noput;
  329. break;
  330. }
  331. coroipcc_dispatch_put (confdb_inst->handle);
  332. /*
  333. * Determine if more messages should be processed
  334. */
  335. if (dispatch_types == CS_DISPATCH_ONE) {
  336. cont = 0;
  337. }
  338. } while (cont);
  339. error_put:
  340. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  341. error_noput:
  342. return (error);
  343. }
  344. cs_error_t confdb_object_create (
  345. confdb_handle_t handle,
  346. hdb_handle_t parent_object_handle,
  347. const void *object_name,
  348. size_t object_name_len,
  349. hdb_handle_t *object_handle)
  350. {
  351. cs_error_t error;
  352. struct confdb_inst *confdb_inst;
  353. struct iovec iov;
  354. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  355. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  356. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  357. if (error != CS_OK) {
  358. return (error);
  359. }
  360. if (confdb_inst->standalone) {
  361. error = CS_OK;
  362. if (confdb_sa_object_create(parent_object_handle,
  363. object_name, object_name_len,
  364. object_handle))
  365. error = CS_ERR_ACCESS;
  366. goto error_exit;
  367. }
  368. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  369. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  370. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  371. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  372. req_lib_confdb_object_create.object_name.length = object_name_len;
  373. iov.iov_base = (char *)&req_lib_confdb_object_create;
  374. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  375. error = coroipcc_msg_send_reply_receive (
  376. confdb_inst->handle,
  377. &iov,
  378. 1,
  379. &res_lib_confdb_object_create,
  380. sizeof (struct res_lib_confdb_object_create));
  381. if (error != CS_OK) {
  382. goto error_exit;
  383. }
  384. error = res_lib_confdb_object_create.header.error;
  385. *object_handle = res_lib_confdb_object_create.object_handle;
  386. error_exit:
  387. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  388. return (error);
  389. }
  390. cs_error_t confdb_object_destroy (
  391. confdb_handle_t handle,
  392. hdb_handle_t object_handle)
  393. {
  394. cs_error_t error;
  395. struct confdb_inst *confdb_inst;
  396. struct iovec iov;
  397. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  398. coroipc_response_header_t res;
  399. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  400. if (error != CS_OK) {
  401. return (error);
  402. }
  403. if (confdb_inst->standalone) {
  404. error = CS_OK;
  405. if (confdb_sa_object_destroy(object_handle))
  406. error = CS_ERR_ACCESS;
  407. goto error_exit;
  408. }
  409. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  410. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  411. req_lib_confdb_object_destroy.object_handle = object_handle;
  412. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  413. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  414. error = coroipcc_msg_send_reply_receive (
  415. confdb_inst->handle,
  416. &iov,
  417. 1,
  418. &res,
  419. sizeof (coroipc_response_header_t));
  420. if (error != CS_OK) {
  421. goto error_exit;
  422. }
  423. error = res.error;
  424. error_exit:
  425. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  426. return (error);
  427. }
  428. cs_error_t confdb_object_parent_get (
  429. confdb_handle_t handle,
  430. hdb_handle_t object_handle,
  431. hdb_handle_t *parent_object_handle)
  432. {
  433. cs_error_t error;
  434. struct confdb_inst *confdb_inst;
  435. struct iovec iov;
  436. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  437. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  438. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  439. if (error != CS_OK) {
  440. return (error);
  441. }
  442. if (confdb_inst->standalone) {
  443. error = CS_OK;
  444. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  445. error = CS_ERR_ACCESS;
  446. goto error_exit;
  447. }
  448. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  449. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  450. req_lib_confdb_object_parent_get.object_handle = object_handle;
  451. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  452. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  453. error = coroipcc_msg_send_reply_receive (
  454. confdb_inst->handle,
  455. &iov,
  456. 1,
  457. &res_lib_confdb_object_parent_get,
  458. sizeof (struct res_lib_confdb_object_parent_get));
  459. if (error != CS_OK) {
  460. goto error_exit;
  461. }
  462. error = res_lib_confdb_object_parent_get.header.error;
  463. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  464. error_exit:
  465. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  466. return (error);
  467. }
  468. static cs_error_t do_find_destroy(
  469. struct confdb_inst *confdb_inst,
  470. hdb_handle_t find_handle)
  471. {
  472. cs_error_t error;
  473. struct iovec iov;
  474. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  475. coroipc_response_header_t res;
  476. if (!find_handle)
  477. return CS_OK;
  478. if (confdb_inst->standalone) {
  479. error = CS_OK;
  480. if (confdb_sa_find_destroy(find_handle))
  481. error = CS_ERR_ACCESS;
  482. goto error_exit;
  483. }
  484. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  485. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  486. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  487. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  488. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  489. error = coroipcc_msg_send_reply_receive (
  490. confdb_inst->handle,
  491. &iov,
  492. 1,
  493. &res,
  494. sizeof (coroipc_response_header_t));
  495. if (error != CS_OK) {
  496. goto error_exit;
  497. }
  498. error = res.error;
  499. error_exit:
  500. return (error);
  501. }
  502. cs_error_t confdb_object_find_destroy(
  503. confdb_handle_t handle,
  504. hdb_handle_t parent_object_handle)
  505. {
  506. struct iter_context *context;
  507. cs_error_t error;
  508. struct confdb_inst *confdb_inst;
  509. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  510. if (error != CS_OK) {
  511. return (error);
  512. }
  513. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  514. error = do_find_destroy(confdb_inst, context->find_handle);
  515. if (error == CS_OK) {
  516. list_del(&context->list);
  517. free(context);
  518. }
  519. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  520. return error;
  521. }
  522. cs_error_t confdb_object_iter_destroy(
  523. confdb_handle_t handle,
  524. hdb_handle_t parent_object_handle)
  525. {
  526. struct iter_context *context;
  527. cs_error_t error;
  528. struct confdb_inst *confdb_inst;
  529. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  530. if (error != CS_OK) {
  531. return (error);
  532. }
  533. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  534. error = do_find_destroy(confdb_inst, context->find_handle);
  535. if (error == CS_OK) {
  536. list_del(&context->list);
  537. free(context);
  538. }
  539. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  540. return error;
  541. }
  542. cs_error_t confdb_key_create (
  543. confdb_handle_t handle,
  544. hdb_handle_t parent_object_handle,
  545. const void *key_name,
  546. size_t key_name_len,
  547. const void *value,
  548. size_t value_len)
  549. {
  550. cs_error_t error;
  551. struct confdb_inst *confdb_inst;
  552. struct iovec iov;
  553. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  554. coroipc_response_header_t res;
  555. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  556. if (error != CS_OK) {
  557. return (error);
  558. }
  559. if (confdb_inst->standalone) {
  560. error = CS_OK;
  561. if (confdb_sa_key_create(parent_object_handle,
  562. key_name, key_name_len,
  563. value, value_len))
  564. error = CS_ERR_ACCESS;
  565. goto error_exit;
  566. }
  567. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  568. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  569. req_lib_confdb_key_create.object_handle = parent_object_handle;
  570. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  571. req_lib_confdb_key_create.key_name.length = key_name_len;
  572. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  573. req_lib_confdb_key_create.value.length = value_len;
  574. iov.iov_base = (char *)&req_lib_confdb_key_create;
  575. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  576. error = coroipcc_msg_send_reply_receive (
  577. confdb_inst->handle,
  578. &iov,
  579. 1,
  580. &res,
  581. sizeof (res));
  582. if (error != CS_OK) {
  583. goto error_exit;
  584. }
  585. error = res.error;
  586. error_exit:
  587. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  588. return (error);
  589. }
  590. cs_error_t confdb_key_create_typed (
  591. confdb_handle_t handle,
  592. hdb_handle_t parent_object_handle,
  593. const char *key_name,
  594. const void *value,
  595. size_t value_len,
  596. confdb_value_types_t type)
  597. {
  598. cs_error_t error;
  599. struct confdb_inst *confdb_inst;
  600. struct iovec iov;
  601. struct req_lib_confdb_key_create_typed request;
  602. coroipc_response_header_t res;
  603. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  604. if (error != CS_OK) {
  605. return (error);
  606. }
  607. if (confdb_inst->standalone) {
  608. error = CS_OK;
  609. if (confdb_sa_key_create_typed(parent_object_handle,
  610. key_name, value, value_len, type))
  611. error = CS_ERR_ACCESS;
  612. goto error_exit;
  613. }
  614. request.header.size = sizeof (struct req_lib_confdb_key_create_typed);
  615. request.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE_TYPED;
  616. request.object_handle = parent_object_handle;
  617. request.key_name.length = strlen(key_name)+1;
  618. memcpy(request.key_name.value, key_name, request.key_name.length);
  619. memcpy(request.value.value, value, value_len);
  620. request.value.length = value_len;
  621. request.type = type;
  622. iov.iov_base = (char *)&request;
  623. iov.iov_len = sizeof (struct req_lib_confdb_key_create_typed);
  624. error = coroipcc_msg_send_reply_receive (
  625. confdb_inst->handle,
  626. &iov,
  627. 1,
  628. &res,
  629. sizeof (res));
  630. if (error != CS_OK) {
  631. goto error_exit;
  632. }
  633. error = res.error;
  634. error_exit:
  635. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  636. return (error);
  637. }
  638. cs_error_t confdb_key_delete (
  639. confdb_handle_t handle,
  640. hdb_handle_t parent_object_handle,
  641. const void *key_name,
  642. size_t key_name_len,
  643. const void *value,
  644. size_t value_len)
  645. {
  646. cs_error_t error;
  647. struct confdb_inst *confdb_inst;
  648. struct iovec iov;
  649. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  650. coroipc_response_header_t res;
  651. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  652. if (error != CS_OK) {
  653. return (error);
  654. }
  655. if (confdb_inst->standalone) {
  656. error = CS_OK;
  657. if (confdb_sa_key_delete(parent_object_handle,
  658. key_name, key_name_len,
  659. value, value_len))
  660. error = CS_ERR_ACCESS;
  661. goto error_exit;
  662. }
  663. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  664. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  665. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  666. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  667. req_lib_confdb_key_delete.key_name.length = key_name_len;
  668. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  669. req_lib_confdb_key_delete.value.length = value_len;
  670. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  671. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  672. error = coroipcc_msg_send_reply_receive (
  673. confdb_inst->handle,
  674. &iov,
  675. 1,
  676. &res,
  677. sizeof (res));
  678. if (error != CS_OK) {
  679. goto error_exit;
  680. }
  681. error = res.error;
  682. error_exit:
  683. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  684. return (error);
  685. }
  686. cs_error_t confdb_key_get (
  687. confdb_handle_t handle,
  688. hdb_handle_t parent_object_handle,
  689. const void *key_name,
  690. size_t key_name_len,
  691. void *value,
  692. size_t *value_len)
  693. {
  694. cs_error_t error;
  695. struct confdb_inst *confdb_inst;
  696. struct iovec iov;
  697. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  698. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  699. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  700. if (error != CS_OK) {
  701. return (error);
  702. }
  703. if (confdb_inst->standalone) {
  704. error = CS_OK;
  705. if (confdb_sa_key_get(parent_object_handle,
  706. key_name, key_name_len,
  707. value, value_len))
  708. error = CS_ERR_ACCESS;
  709. goto error_exit;
  710. }
  711. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  712. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  713. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  714. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  715. req_lib_confdb_key_get.key_name.length = key_name_len;
  716. iov.iov_base = (char *)&req_lib_confdb_key_get;
  717. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  718. error = coroipcc_msg_send_reply_receive (
  719. confdb_inst->handle,
  720. &iov,
  721. 1,
  722. &res_lib_confdb_key_get,
  723. sizeof (struct res_lib_confdb_key_get));
  724. if (error != CS_OK) {
  725. goto error_exit;
  726. }
  727. error = res_lib_confdb_key_get.header.error;
  728. if (error == CS_OK) {
  729. *value_len = res_lib_confdb_key_get.value.length;
  730. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  731. }
  732. error_exit:
  733. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  734. return (error);
  735. }
  736. cs_error_t confdb_key_get_typed (
  737. confdb_handle_t handle,
  738. hdb_handle_t parent_object_handle,
  739. const char *key_name,
  740. void *value,
  741. size_t *value_len,
  742. confdb_value_types_t *type)
  743. {
  744. cs_error_t error;
  745. struct confdb_inst *confdb_inst;
  746. struct iovec iov;
  747. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  748. struct res_lib_confdb_key_get_typed response;
  749. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  750. if (error != CS_OK) {
  751. return (error);
  752. }
  753. if (confdb_inst->standalone) {
  754. error = CS_OK;
  755. if (confdb_sa_key_get_typed(parent_object_handle,
  756. key_name, value, value_len, (int*)type))
  757. error = CS_ERR_ACCESS;
  758. goto error_exit;
  759. }
  760. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  761. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED;
  762. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  763. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  764. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  765. iov.iov_base = (char *)&req_lib_confdb_key_get;
  766. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  767. error = coroipcc_msg_send_reply_receive (
  768. confdb_inst->handle,
  769. &iov,
  770. 1,
  771. &response,
  772. sizeof (struct res_lib_confdb_key_get_typed));
  773. if (error != CS_OK) {
  774. goto error_exit;
  775. }
  776. error = response.header.error;
  777. if (error == CS_OK) {
  778. *value_len = response.value.length;
  779. *type = response.type;
  780. memcpy(value, response.value.value, *value_len);
  781. }
  782. error_exit:
  783. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  784. return (error);
  785. }
  786. cs_error_t confdb_key_increment (
  787. confdb_handle_t handle,
  788. hdb_handle_t parent_object_handle,
  789. const void *key_name,
  790. size_t key_name_len,
  791. unsigned int *value)
  792. {
  793. cs_error_t error;
  794. struct confdb_inst *confdb_inst;
  795. struct iovec iov;
  796. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  797. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  798. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  799. if (error != CS_OK) {
  800. return (error);
  801. }
  802. if (confdb_inst->standalone) {
  803. error = CS_OK;
  804. if (confdb_sa_key_increment(parent_object_handle,
  805. key_name, key_name_len,
  806. value))
  807. error = CS_ERR_ACCESS;
  808. goto error_exit;
  809. }
  810. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  811. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  812. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  813. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  814. req_lib_confdb_key_get.key_name.length = key_name_len;
  815. iov.iov_base = (char *)&req_lib_confdb_key_get;
  816. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  817. error = coroipcc_msg_send_reply_receive (
  818. confdb_inst->handle,
  819. &iov,
  820. 1,
  821. &res_lib_confdb_key_incdec,
  822. sizeof (struct res_lib_confdb_key_incdec));
  823. if (error != CS_OK) {
  824. goto error_exit;
  825. }
  826. error = res_lib_confdb_key_incdec.header.error;
  827. if (error == CS_OK) {
  828. *value = res_lib_confdb_key_incdec.value;
  829. }
  830. error_exit:
  831. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  832. return (error);
  833. }
  834. cs_error_t confdb_key_decrement (
  835. confdb_handle_t handle,
  836. hdb_handle_t parent_object_handle,
  837. const void *key_name,
  838. size_t key_name_len,
  839. unsigned int *value)
  840. {
  841. cs_error_t error;
  842. struct confdb_inst *confdb_inst;
  843. struct iovec iov;
  844. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  845. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  846. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  847. if (error != CS_OK) {
  848. return (error);
  849. }
  850. if (confdb_inst->standalone) {
  851. error = CS_OK;
  852. if (confdb_sa_key_decrement(parent_object_handle,
  853. key_name, key_name_len,
  854. value))
  855. error = CS_ERR_ACCESS;
  856. goto error_exit;
  857. }
  858. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  859. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  860. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  861. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  862. req_lib_confdb_key_get.key_name.length = key_name_len;
  863. iov.iov_base = (char *)&req_lib_confdb_key_get;
  864. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  865. error = coroipcc_msg_send_reply_receive (
  866. confdb_inst->handle,
  867. &iov,
  868. 1,
  869. &res_lib_confdb_key_incdec,
  870. sizeof (struct res_lib_confdb_key_incdec));
  871. if (error != CS_OK) {
  872. goto error_exit;
  873. }
  874. error = res_lib_confdb_key_incdec.header.error;
  875. if (error == CS_OK) {
  876. *value = res_lib_confdb_key_incdec.value;
  877. }
  878. error_exit:
  879. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  880. return (error);
  881. }
  882. cs_error_t confdb_key_replace (
  883. confdb_handle_t handle,
  884. hdb_handle_t parent_object_handle,
  885. const void *key_name,
  886. size_t key_name_len,
  887. const void *old_value,
  888. size_t old_value_len,
  889. const void *new_value,
  890. size_t new_value_len)
  891. {
  892. cs_error_t error;
  893. struct confdb_inst *confdb_inst;
  894. struct iovec iov;
  895. struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
  896. coroipc_response_header_t res;
  897. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  898. if (error != CS_OK) {
  899. return (error);
  900. }
  901. if (confdb_inst->standalone) {
  902. error = CS_OK;
  903. if (confdb_sa_key_replace(parent_object_handle,
  904. key_name, key_name_len,
  905. old_value, old_value_len,
  906. new_value, new_value_len))
  907. error = CS_ERR_ACCESS;
  908. goto error_exit;
  909. }
  910. req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
  911. req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
  912. req_lib_confdb_key_replace.object_handle = parent_object_handle;
  913. memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
  914. req_lib_confdb_key_replace.key_name.length = key_name_len;
  915. memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
  916. req_lib_confdb_key_replace.old_value.length = old_value_len;
  917. memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
  918. req_lib_confdb_key_replace.new_value.length = new_value_len;
  919. iov.iov_base = (char *)&req_lib_confdb_key_replace;
  920. iov.iov_len = sizeof (struct req_lib_confdb_key_replace);
  921. error = coroipcc_msg_send_reply_receive (
  922. confdb_inst->handle,
  923. &iov,
  924. 1,
  925. &res,
  926. sizeof (res));
  927. if (error != CS_OK) {
  928. goto error_exit;
  929. }
  930. error = res.error;
  931. error_exit:
  932. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  933. return (error);
  934. }
  935. cs_error_t confdb_object_iter_start (
  936. confdb_handle_t handle,
  937. hdb_handle_t object_handle)
  938. {
  939. struct confdb_inst *confdb_inst;
  940. cs_error_t error = CS_OK;
  941. struct iter_context *context;
  942. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  943. if (error != CS_OK) {
  944. return (error);
  945. }
  946. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  947. if (!context) {
  948. context = malloc(sizeof(struct iter_context));
  949. if (!context) {
  950. error = CS_ERR_NO_MEMORY;
  951. goto ret;
  952. }
  953. context->parent_object_handle = object_handle;
  954. context->find_handle = 0;
  955. list_add(&context->list, &confdb_inst->object_iter_head);
  956. }
  957. /* Start a new find context */
  958. if (context->find_handle) {
  959. (void)do_find_destroy(confdb_inst, context->find_handle);
  960. context->find_handle = 0;
  961. }
  962. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  963. ret:
  964. return error;
  965. }
  966. cs_error_t confdb_key_iter_start (
  967. confdb_handle_t handle,
  968. hdb_handle_t object_handle)
  969. {
  970. struct confdb_inst *confdb_inst;
  971. cs_error_t error = CS_OK;
  972. struct iter_context *context;
  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. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  978. if (!context) {
  979. context = malloc(sizeof(struct iter_context));
  980. if (!context) {
  981. error = CS_ERR_NO_MEMORY;
  982. goto ret;
  983. }
  984. context->parent_object_handle = object_handle;
  985. list_add(&context->list, &confdb_inst->key_iter_head);
  986. }
  987. context->find_handle = 0;
  988. context->next_entry = 0;
  989. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  990. ret:
  991. return error;
  992. }
  993. cs_error_t confdb_object_find_start (
  994. confdb_handle_t handle,
  995. hdb_handle_t parent_object_handle)
  996. {
  997. struct confdb_inst *confdb_inst;
  998. cs_error_t error = CS_OK;
  999. struct iter_context *context;
  1000. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1001. if (error != CS_OK) {
  1002. return (error);
  1003. }
  1004. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1005. if (!context) {
  1006. context = malloc(sizeof(struct iter_context));
  1007. if (!context) {
  1008. error = CS_ERR_NO_MEMORY;
  1009. goto ret;
  1010. }
  1011. context->find_handle = 0;
  1012. context->parent_object_handle = parent_object_handle;
  1013. list_add(&context->list, &confdb_inst->object_find_head);
  1014. }
  1015. /* Start a new find context */
  1016. if (context->find_handle) {
  1017. (void)do_find_destroy(confdb_inst, context->find_handle);
  1018. context->find_handle = 0;
  1019. }
  1020. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1021. ret:
  1022. return error;
  1023. }
  1024. cs_error_t confdb_object_find (
  1025. confdb_handle_t handle,
  1026. hdb_handle_t parent_object_handle,
  1027. const void *object_name,
  1028. size_t object_name_len,
  1029. hdb_handle_t *object_handle)
  1030. {
  1031. cs_error_t error;
  1032. struct confdb_inst *confdb_inst;
  1033. struct iovec iov;
  1034. struct iter_context *context;
  1035. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  1036. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  1037. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1038. if (error != CS_OK) {
  1039. return (error);
  1040. }
  1041. /* You MUST call confdb_object_find_start first */
  1042. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1043. if (!context) {
  1044. error = CS_ERR_CONTEXT_NOT_FOUND;
  1045. goto error_exit;
  1046. }
  1047. if (confdb_inst->standalone) {
  1048. error = CS_OK;
  1049. if (confdb_sa_object_find(parent_object_handle,
  1050. &context->find_handle,
  1051. object_handle,
  1052. object_name, object_name_len))
  1053. error = CS_ERR_ACCESS;
  1054. goto error_exit;
  1055. }
  1056. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  1057. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  1058. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  1059. req_lib_confdb_object_find.find_handle = context->find_handle;
  1060. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  1061. req_lib_confdb_object_find.object_name.length = object_name_len;
  1062. iov.iov_base = (char *)&req_lib_confdb_object_find;
  1063. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  1064. error = coroipcc_msg_send_reply_receive (
  1065. confdb_inst->handle,
  1066. &iov,
  1067. 1,
  1068. &res_lib_confdb_object_find,
  1069. sizeof (struct res_lib_confdb_object_find));
  1070. if (error != CS_OK) {
  1071. goto error_exit;
  1072. }
  1073. error = res_lib_confdb_object_find.header.error;
  1074. *object_handle = res_lib_confdb_object_find.object_handle;
  1075. context->find_handle = res_lib_confdb_object_find.find_handle;
  1076. error_exit:
  1077. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1078. return (error);
  1079. }
  1080. cs_error_t confdb_object_iter (
  1081. confdb_handle_t handle,
  1082. hdb_handle_t parent_object_handle,
  1083. hdb_handle_t *object_handle,
  1084. void *object_name,
  1085. size_t *object_name_len)
  1086. {
  1087. cs_error_t error;
  1088. struct confdb_inst *confdb_inst;
  1089. struct iovec iov;
  1090. struct iter_context *context;
  1091. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1092. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1093. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1094. if (error != CS_OK) {
  1095. return (error);
  1096. }
  1097. /* You MUST call confdb_object_iter_start first */
  1098. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1099. if (!context) {
  1100. error = CS_ERR_CONTEXT_NOT_FOUND;
  1101. goto error_exit;
  1102. }
  1103. if (confdb_inst->standalone) {
  1104. error = CS_OK;
  1105. *object_name_len = 0;
  1106. if (confdb_sa_object_iter(parent_object_handle,
  1107. &context->find_handle,
  1108. object_handle,
  1109. NULL, 0,
  1110. object_name, object_name_len))
  1111. error = CS_ERR_ACCESS;
  1112. goto sa_exit;
  1113. }
  1114. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1115. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1116. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1117. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1118. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1119. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1120. error = coroipcc_msg_send_reply_receive (
  1121. confdb_inst->handle,
  1122. &iov,
  1123. 1,
  1124. &res_lib_confdb_object_iter,
  1125. sizeof (struct res_lib_confdb_object_iter));
  1126. if (error != CS_OK) {
  1127. goto error_exit;
  1128. }
  1129. error = res_lib_confdb_object_iter.header.error;
  1130. if (error == CS_OK) {
  1131. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1132. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1133. *object_handle = res_lib_confdb_object_iter.object_handle;
  1134. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1135. }
  1136. sa_exit:
  1137. error_exit:
  1138. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1139. return (error);
  1140. }
  1141. cs_error_t confdb_key_iter (
  1142. confdb_handle_t handle,
  1143. hdb_handle_t parent_object_handle,
  1144. void *key_name,
  1145. size_t *key_name_len,
  1146. void *value,
  1147. size_t *value_len)
  1148. {
  1149. cs_error_t error;
  1150. struct confdb_inst *confdb_inst;
  1151. struct iovec iov;
  1152. struct iter_context *context;
  1153. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1154. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1155. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1156. if (error != CS_OK) {
  1157. return (error);
  1158. }
  1159. /* You MUST call confdb_key_iter_start first */
  1160. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1161. if (!context) {
  1162. error = CS_ERR_CONTEXT_NOT_FOUND;
  1163. goto error_exit;
  1164. }
  1165. if (confdb_inst->standalone) {
  1166. error = CS_OK;
  1167. if (confdb_sa_key_iter(parent_object_handle,
  1168. context->next_entry,
  1169. key_name, key_name_len,
  1170. value, value_len))
  1171. error = CS_ERR_ACCESS;
  1172. goto sa_exit;
  1173. }
  1174. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1175. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1176. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1177. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1178. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1179. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1180. error = coroipcc_msg_send_reply_receive (
  1181. confdb_inst->handle,
  1182. &iov,
  1183. 1,
  1184. &res_lib_confdb_key_iter,
  1185. sizeof (struct res_lib_confdb_key_iter));
  1186. if (error != CS_OK) {
  1187. goto error_exit;
  1188. }
  1189. error = res_lib_confdb_key_iter.header.error;
  1190. if (error == CS_OK) {
  1191. char* key_name_str = (char*)key_name;
  1192. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1193. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1194. key_name_str[res_lib_confdb_key_iter.key_name.length] = '\0';
  1195. *value_len = res_lib_confdb_key_iter.value.length;
  1196. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1197. }
  1198. sa_exit:
  1199. context->next_entry++;
  1200. error_exit:
  1201. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1202. return (error);
  1203. }
  1204. cs_error_t confdb_key_iter_typed (
  1205. confdb_handle_t handle,
  1206. hdb_handle_t parent_object_handle,
  1207. char *key_name,
  1208. void *value,
  1209. size_t *value_len,
  1210. confdb_value_types_t *type)
  1211. {
  1212. cs_error_t error;
  1213. struct confdb_inst *confdb_inst;
  1214. struct iovec iov;
  1215. struct iter_context *context;
  1216. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1217. struct res_lib_confdb_key_iter_typed response;
  1218. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1219. if (error != CS_OK) {
  1220. return (error);
  1221. }
  1222. /* You MUST call confdb_key_iter_start first */
  1223. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1224. if (!context) {
  1225. error = CS_ERR_CONTEXT_NOT_FOUND;
  1226. goto error_exit;
  1227. }
  1228. if (confdb_inst->standalone) {
  1229. error = CS_OK;
  1230. if (confdb_sa_key_iter_typed(parent_object_handle,
  1231. context->next_entry,
  1232. key_name,
  1233. value, value_len, (int*)type))
  1234. error = CS_ERR_ACCESS;
  1235. goto sa_exit;
  1236. }
  1237. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1238. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED;
  1239. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1240. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1241. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1242. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1243. error = coroipcc_msg_send_reply_receive (
  1244. confdb_inst->handle,
  1245. &iov,
  1246. 1,
  1247. &response,
  1248. sizeof (struct res_lib_confdb_key_iter_typed));
  1249. if (error != CS_OK) {
  1250. goto error_exit;
  1251. }
  1252. error = response.header.error;
  1253. if (error == CS_OK) {
  1254. memcpy(key_name, response.key_name.value, response.key_name.length);
  1255. key_name[response.key_name.length] = '\0';
  1256. *value_len = response.value.length;
  1257. memcpy(value, response.value.value, *value_len);
  1258. *type = response.type;
  1259. }
  1260. sa_exit:
  1261. context->next_entry++;
  1262. error_exit:
  1263. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1264. return (error);
  1265. }
  1266. cs_error_t confdb_write (
  1267. confdb_handle_t handle,
  1268. char *error_text,
  1269. size_t errbuf_len)
  1270. {
  1271. cs_error_t error;
  1272. struct confdb_inst *confdb_inst;
  1273. struct iovec iov;
  1274. coroipc_request_header_t req;
  1275. struct res_lib_confdb_write res_lib_confdb_write;
  1276. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1277. if (error != CS_OK) {
  1278. /* FIXME: set error_text */
  1279. return (error);
  1280. }
  1281. if (confdb_inst->standalone) {
  1282. error = CS_OK;
  1283. if (confdb_sa_write(error_text, errbuf_len))
  1284. error = CS_ERR_ACCESS;
  1285. goto error_exit;
  1286. }
  1287. req.size = sizeof (coroipc_request_header_t);
  1288. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1289. iov.iov_base = (char *)&req;
  1290. iov.iov_len = sizeof (coroipc_request_header_t);
  1291. error = coroipcc_msg_send_reply_receive (
  1292. confdb_inst->handle,
  1293. &iov,
  1294. 1,
  1295. &res_lib_confdb_write,
  1296. sizeof (struct res_lib_confdb_write));
  1297. if (error != CS_OK) {
  1298. /* FIXME: set error_text */
  1299. goto error_exit;
  1300. }
  1301. error = res_lib_confdb_write.header.error;
  1302. if (res_lib_confdb_write.error.length) {
  1303. memcpy(error_text, res_lib_confdb_write.error.value,
  1304. MIN(res_lib_confdb_write.error.length,errbuf_len));
  1305. error_text[errbuf_len-1] = '\0';
  1306. }
  1307. error_exit:
  1308. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1309. return (error);
  1310. }
  1311. cs_error_t confdb_reload (
  1312. confdb_handle_t handle,
  1313. int flush,
  1314. char *error_text,
  1315. size_t errbuf_len)
  1316. {
  1317. cs_error_t error;
  1318. struct confdb_inst *confdb_inst;
  1319. struct iovec iov;
  1320. struct res_lib_confdb_reload res_lib_confdb_reload;
  1321. struct req_lib_confdb_reload req_lib_confdb_reload;
  1322. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1323. if (error != CS_OK) {
  1324. /* FIXME: set error_text */
  1325. return (error);
  1326. }
  1327. if (confdb_inst->standalone) {
  1328. error = CS_OK;
  1329. if (confdb_sa_reload(flush, error_text, errbuf_len))
  1330. error = CS_ERR_ACCESS;
  1331. goto error_exit;
  1332. }
  1333. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1334. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1335. req_lib_confdb_reload.flush = flush;
  1336. iov.iov_base = (char *)&req_lib_confdb_reload;
  1337. iov.iov_len = sizeof (req_lib_confdb_reload);
  1338. error = coroipcc_msg_send_reply_receive (
  1339. confdb_inst->handle,
  1340. &iov,
  1341. 1,
  1342. &res_lib_confdb_reload,
  1343. sizeof (struct res_lib_confdb_reload));
  1344. if (error != CS_OK) {
  1345. /* FIXME: set error_text */
  1346. goto error_exit;
  1347. }
  1348. error = res_lib_confdb_reload.header.error;
  1349. if(res_lib_confdb_reload.error.length) {
  1350. memcpy(error_text, res_lib_confdb_reload.error.value,
  1351. MIN(res_lib_confdb_reload.error.length,errbuf_len));
  1352. error_text[errbuf_len-1] = '\0';
  1353. }
  1354. error_exit:
  1355. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1356. return (error);
  1357. }
  1358. cs_error_t confdb_track_changes (
  1359. confdb_handle_t handle,
  1360. hdb_handle_t object_handle,
  1361. unsigned int flags)
  1362. {
  1363. cs_error_t error;
  1364. struct confdb_inst *confdb_inst;
  1365. struct iovec iov;
  1366. struct req_lib_confdb_object_track_start req;
  1367. coroipc_response_header_t res;
  1368. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1369. if (error != CS_OK) {
  1370. return (error);
  1371. }
  1372. if (confdb_inst->standalone) {
  1373. error = CS_ERR_NOT_SUPPORTED;
  1374. goto error_exit;
  1375. }
  1376. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1377. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1378. req.object_handle = object_handle;
  1379. req.flags = flags;
  1380. iov.iov_base = (char *)&req;
  1381. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1382. error = coroipcc_msg_send_reply_receive (
  1383. confdb_inst->handle,
  1384. &iov,
  1385. 1,
  1386. &res,
  1387. sizeof (coroipc_response_header_t));
  1388. if (error != CS_OK) {
  1389. goto error_exit;
  1390. }
  1391. error = res.error;
  1392. error_exit:
  1393. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1394. return (error);
  1395. }
  1396. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1397. {
  1398. cs_error_t error;
  1399. struct confdb_inst *confdb_inst;
  1400. struct iovec iov;
  1401. coroipc_request_header_t req;
  1402. coroipc_response_header_t res;
  1403. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1404. if (error != CS_OK) {
  1405. return (error);
  1406. }
  1407. if (confdb_inst->standalone) {
  1408. error = CS_ERR_NOT_SUPPORTED;
  1409. goto error_exit;
  1410. }
  1411. req.size = sizeof (coroipc_request_header_t);
  1412. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1413. iov.iov_base = (char *)&req;
  1414. iov.iov_len = sizeof (coroipc_request_header_t);
  1415. error = coroipcc_msg_send_reply_receive (
  1416. confdb_inst->handle,
  1417. &iov,
  1418. 1,
  1419. &res,
  1420. sizeof (coroipc_response_header_t));
  1421. if (error != CS_OK) {
  1422. goto error_exit;
  1423. }
  1424. error = res.error;
  1425. error_exit:
  1426. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1427. return (error);
  1428. }