confdb.c 45 KB

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