confdb.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  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. memcpy (&confdb_inst->callbacks, callbacks, sizeof (confdb_callbacks_t));
  137. list_init (&confdb_inst->object_find_head);
  138. list_init (&confdb_inst->object_iter_head);
  139. list_init (&confdb_inst->key_iter_head);
  140. (void)hdb_handle_put (&confdb_handle_t_db, *handle);
  141. return (CS_OK);
  142. error_put_destroy:
  143. (void)hdb_handle_put (&confdb_handle_t_db, *handle);
  144. error_destroy:
  145. (void)hdb_handle_destroy (&confdb_handle_t_db, *handle);
  146. error_no_destroy:
  147. return (error);
  148. }
  149. cs_error_t confdb_finalize (
  150. confdb_handle_t handle)
  151. {
  152. struct confdb_inst *confdb_inst;
  153. cs_error_t error;
  154. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  155. if (error != CS_OK) {
  156. return (error);
  157. }
  158. /*
  159. * Another thread has already started finalizing
  160. */
  161. if (confdb_inst->finalize) {
  162. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  163. return (CS_ERR_BAD_HANDLE);
  164. }
  165. confdb_inst->finalize = 1;
  166. /* Free saved context handles */
  167. free_context_list(confdb_inst, &confdb_inst->object_find_head);
  168. free_context_list(confdb_inst, &confdb_inst->object_iter_head);
  169. free_context_list(confdb_inst, &confdb_inst->key_iter_head);
  170. if (!confdb_inst->standalone) {
  171. coroipcc_service_disconnect (confdb_inst->handle);
  172. }
  173. (void)hdb_handle_destroy (&confdb_handle_t_db, handle);
  174. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  175. return (CS_OK);
  176. }
  177. cs_error_t confdb_fd_get (
  178. confdb_handle_t handle,
  179. int *fd)
  180. {
  181. cs_error_t error;
  182. struct confdb_inst *confdb_inst;
  183. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  184. if (error != CS_OK) {
  185. return (error);
  186. }
  187. error = coroipcc_fd_get (confdb_inst->handle, fd);
  188. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  189. return (error);
  190. }
  191. cs_error_t confdb_context_get (
  192. confdb_handle_t handle,
  193. const void **context)
  194. {
  195. cs_error_t error;
  196. struct confdb_inst *confdb_inst;
  197. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  198. if (error != CS_OK) {
  199. return (error);
  200. }
  201. *context = confdb_inst->context;
  202. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  203. return (CS_OK);
  204. }
  205. cs_error_t confdb_context_set (
  206. confdb_handle_t handle,
  207. const void *context)
  208. {
  209. cs_error_t error;
  210. struct confdb_inst *confdb_inst;
  211. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  212. if (error != CS_OK) {
  213. return (error);
  214. }
  215. confdb_inst->context = context;
  216. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  217. return (CS_OK);
  218. }
  219. cs_error_t confdb_dispatch (
  220. confdb_handle_t handle,
  221. cs_dispatch_flags_t dispatch_types)
  222. {
  223. int timeout = -1;
  224. cs_error_t error;
  225. int cont = 1; /* always continue do loop except when set to 0 */
  226. struct confdb_inst *confdb_inst;
  227. confdb_callbacks_t callbacks;
  228. struct res_lib_confdb_key_change_callback *res_key_changed_pt;
  229. struct res_lib_confdb_object_create_callback *res_object_created_pt;
  230. struct res_lib_confdb_object_destroy_callback *res_object_destroyed_pt;
  231. coroipc_response_header_t *dispatch_data;
  232. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  233. if (error != CS_OK) {
  234. return (error);
  235. }
  236. if (confdb_inst->standalone) {
  237. error = CS_ERR_NOT_SUPPORTED;
  238. goto error_put;
  239. }
  240. /*
  241. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  242. * wait indefinately for SA_DISPATCH_BLOCKING
  243. */
  244. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  245. timeout = 0;
  246. }
  247. do {
  248. error = coroipcc_dispatch_get (
  249. confdb_inst->handle,
  250. (void **)&dispatch_data,
  251. timeout);
  252. if (error == CS_ERR_BAD_HANDLE) {
  253. error = CS_OK;
  254. goto error_put;
  255. }
  256. if (error != CS_OK) {
  257. goto error_put;
  258. }
  259. /*
  260. * Make copy of callbacks, message data, unlock instance, and call callback
  261. * A risk of this dispatch method is that the callback routines may
  262. * operate at the same time that confdbFinalize has been called.
  263. */
  264. memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
  265. /*
  266. * Dispatch incoming message
  267. */
  268. switch (dispatch_data->id) {
  269. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
  270. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
  271. callbacks.confdb_key_change_notify_fn(handle,
  272. res_key_changed_pt->change_type,
  273. res_key_changed_pt->object_handle,
  274. res_key_changed_pt->parent_object_handle,
  275. res_key_changed_pt->object_name.value,
  276. res_key_changed_pt->object_name.length,
  277. res_key_changed_pt->key_name.value,
  278. res_key_changed_pt->key_name.length,
  279. res_key_changed_pt->key_value.value,
  280. res_key_changed_pt->key_value.length);
  281. break;
  282. case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
  283. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)dispatch_data;
  284. callbacks.confdb_object_create_change_notify_fn(handle,
  285. res_object_created_pt->object_handle,
  286. res_object_created_pt->parent_object_handle,
  287. res_object_created_pt->name.value,
  288. res_object_created_pt->name.length);
  289. break;
  290. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  291. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)dispatch_data;
  292. callbacks.confdb_object_delete_change_notify_fn(handle,
  293. res_object_destroyed_pt->parent_object_handle,
  294. res_object_destroyed_pt->name.value,
  295. res_object_destroyed_pt->name.length);
  296. break;
  297. default:
  298. coroipcc_dispatch_put (confdb_inst->handle);
  299. error = CS_ERR_LIBRARY;
  300. goto error_noput;
  301. break;
  302. }
  303. coroipcc_dispatch_put (confdb_inst->handle);
  304. /*
  305. * Determine if more messages should be processed
  306. * */
  307. switch (dispatch_types) {
  308. case CONFDB_DISPATCH_ONE:
  309. cont = 0;
  310. break;
  311. case CONFDB_DISPATCH_ALL:
  312. break;
  313. case CONFDB_DISPATCH_BLOCKING:
  314. break;
  315. }
  316. } while (cont);
  317. error_put:
  318. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  319. error_noput:
  320. return (error);
  321. }
  322. cs_error_t confdb_object_create (
  323. confdb_handle_t handle,
  324. hdb_handle_t parent_object_handle,
  325. const void *object_name,
  326. size_t object_name_len,
  327. hdb_handle_t *object_handle)
  328. {
  329. cs_error_t error;
  330. struct confdb_inst *confdb_inst;
  331. struct iovec iov;
  332. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  333. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  334. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  335. if (error != CS_OK) {
  336. return (error);
  337. }
  338. if (confdb_inst->standalone) {
  339. error = CS_OK;
  340. if (confdb_sa_object_create(parent_object_handle,
  341. object_name, object_name_len,
  342. object_handle))
  343. error = CS_ERR_ACCESS;
  344. goto error_exit;
  345. }
  346. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  347. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  348. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  349. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  350. req_lib_confdb_object_create.object_name.length = object_name_len;
  351. iov.iov_base = (char *)&req_lib_confdb_object_create;
  352. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  353. error = coroipcc_msg_send_reply_receive (
  354. confdb_inst->handle,
  355. &iov,
  356. 1,
  357. &res_lib_confdb_object_create,
  358. sizeof (struct res_lib_confdb_object_create));
  359. if (error != CS_OK) {
  360. goto error_exit;
  361. }
  362. error = res_lib_confdb_object_create.header.error;
  363. *object_handle = res_lib_confdb_object_create.object_handle;
  364. error_exit:
  365. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  366. return (error);
  367. }
  368. cs_error_t confdb_object_destroy (
  369. confdb_handle_t handle,
  370. hdb_handle_t object_handle)
  371. {
  372. cs_error_t error;
  373. struct confdb_inst *confdb_inst;
  374. struct iovec iov;
  375. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  376. coroipc_response_header_t res;
  377. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  378. if (error != CS_OK) {
  379. return (error);
  380. }
  381. if (confdb_inst->standalone) {
  382. error = CS_OK;
  383. if (confdb_sa_object_destroy(object_handle))
  384. error = CS_ERR_ACCESS;
  385. goto error_exit;
  386. }
  387. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  388. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  389. req_lib_confdb_object_destroy.object_handle = object_handle;
  390. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  391. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  392. error = coroipcc_msg_send_reply_receive (
  393. confdb_inst->handle,
  394. &iov,
  395. 1,
  396. &res,
  397. sizeof (coroipc_response_header_t));
  398. if (error != CS_OK) {
  399. goto error_exit;
  400. }
  401. error = res.error;
  402. error_exit:
  403. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  404. return (error);
  405. }
  406. cs_error_t confdb_object_parent_get (
  407. confdb_handle_t handle,
  408. hdb_handle_t object_handle,
  409. hdb_handle_t *parent_object_handle)
  410. {
  411. cs_error_t error;
  412. struct confdb_inst *confdb_inst;
  413. struct iovec iov;
  414. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  415. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  416. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  417. if (error != CS_OK) {
  418. return (error);
  419. }
  420. if (confdb_inst->standalone) {
  421. error = CS_OK;
  422. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  423. error = CS_ERR_ACCESS;
  424. goto error_exit;
  425. }
  426. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  427. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  428. req_lib_confdb_object_parent_get.object_handle = object_handle;
  429. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  430. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  431. error = coroipcc_msg_send_reply_receive (
  432. confdb_inst->handle,
  433. &iov,
  434. 1,
  435. &res_lib_confdb_object_parent_get,
  436. sizeof (struct res_lib_confdb_object_parent_get));
  437. if (error != CS_OK) {
  438. goto error_exit;
  439. }
  440. error = res_lib_confdb_object_parent_get.header.error;
  441. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  442. error_exit:
  443. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  444. return (error);
  445. }
  446. static cs_error_t do_find_destroy(
  447. struct confdb_inst *confdb_inst,
  448. hdb_handle_t find_handle)
  449. {
  450. cs_error_t error;
  451. struct iovec iov;
  452. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  453. coroipc_response_header_t res;
  454. if (!find_handle)
  455. return CS_OK;
  456. if (confdb_inst->standalone) {
  457. error = CS_OK;
  458. if (confdb_sa_find_destroy(find_handle))
  459. error = CS_ERR_ACCESS;
  460. goto error_exit;
  461. }
  462. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  463. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  464. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  465. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  466. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  467. error = coroipcc_msg_send_reply_receive (
  468. confdb_inst->handle,
  469. &iov,
  470. 1,
  471. &res,
  472. sizeof (coroipc_response_header_t));
  473. if (error != CS_OK) {
  474. goto error_exit;
  475. }
  476. error = res.error;
  477. error_exit:
  478. return (error);
  479. }
  480. cs_error_t confdb_object_find_destroy(
  481. confdb_handle_t handle,
  482. hdb_handle_t parent_object_handle)
  483. {
  484. struct iter_context *context;
  485. cs_error_t error;
  486. struct confdb_inst *confdb_inst;
  487. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  488. if (error != CS_OK) {
  489. return (error);
  490. }
  491. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  492. error = do_find_destroy(confdb_inst, context->find_handle);
  493. if (error == CS_OK) {
  494. list_del(&context->list);
  495. free(context);
  496. }
  497. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  498. return error;
  499. }
  500. cs_error_t confdb_object_iter_destroy(
  501. confdb_handle_t handle,
  502. hdb_handle_t parent_object_handle)
  503. {
  504. struct iter_context *context;
  505. cs_error_t error;
  506. struct confdb_inst *confdb_inst;
  507. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  508. if (error != CS_OK) {
  509. return (error);
  510. }
  511. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  512. error = do_find_destroy(confdb_inst, context->find_handle);
  513. if (error == CS_OK) {
  514. list_del(&context->list);
  515. free(context);
  516. }
  517. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  518. return error;
  519. }
  520. cs_error_t confdb_key_create (
  521. confdb_handle_t handle,
  522. hdb_handle_t parent_object_handle,
  523. const void *key_name,
  524. size_t key_name_len,
  525. const void *value,
  526. size_t value_len)
  527. {
  528. cs_error_t error;
  529. struct confdb_inst *confdb_inst;
  530. struct iovec iov;
  531. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  532. coroipc_response_header_t res;
  533. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  534. if (error != CS_OK) {
  535. return (error);
  536. }
  537. if (confdb_inst->standalone) {
  538. error = CS_OK;
  539. if (confdb_sa_key_create(parent_object_handle,
  540. key_name, key_name_len,
  541. value, value_len))
  542. error = CS_ERR_ACCESS;
  543. goto error_exit;
  544. }
  545. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  546. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  547. req_lib_confdb_key_create.object_handle = parent_object_handle;
  548. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  549. req_lib_confdb_key_create.key_name.length = key_name_len;
  550. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  551. req_lib_confdb_key_create.value.length = value_len;
  552. iov.iov_base = (char *)&req_lib_confdb_key_create;
  553. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  554. error = coroipcc_msg_send_reply_receive (
  555. confdb_inst->handle,
  556. &iov,
  557. 1,
  558. &res,
  559. sizeof (res));
  560. if (error != CS_OK) {
  561. goto error_exit;
  562. }
  563. error = res.error;
  564. error_exit:
  565. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  566. return (error);
  567. }
  568. cs_error_t confdb_key_delete (
  569. confdb_handle_t handle,
  570. hdb_handle_t parent_object_handle,
  571. const void *key_name,
  572. size_t key_name_len,
  573. const void *value,
  574. size_t value_len)
  575. {
  576. cs_error_t error;
  577. struct confdb_inst *confdb_inst;
  578. struct iovec iov;
  579. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  580. coroipc_response_header_t res;
  581. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  582. if (error != CS_OK) {
  583. return (error);
  584. }
  585. if (confdb_inst->standalone) {
  586. error = CS_OK;
  587. if (confdb_sa_key_delete(parent_object_handle,
  588. key_name, key_name_len,
  589. value, value_len))
  590. error = CS_ERR_ACCESS;
  591. goto error_exit;
  592. }
  593. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  594. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  595. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  596. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  597. req_lib_confdb_key_delete.key_name.length = key_name_len;
  598. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  599. req_lib_confdb_key_delete.value.length = value_len;
  600. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  601. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  602. error = coroipcc_msg_send_reply_receive (
  603. confdb_inst->handle,
  604. &iov,
  605. 1,
  606. &res,
  607. sizeof (res));
  608. if (error != CS_OK) {
  609. goto error_exit;
  610. }
  611. error = res.error;
  612. error_exit:
  613. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  614. return (error);
  615. }
  616. cs_error_t confdb_key_get (
  617. confdb_handle_t handle,
  618. hdb_handle_t parent_object_handle,
  619. const void *key_name,
  620. size_t key_name_len,
  621. void *value,
  622. size_t *value_len)
  623. {
  624. cs_error_t error;
  625. struct confdb_inst *confdb_inst;
  626. struct iovec iov;
  627. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  628. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  629. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  630. if (error != CS_OK) {
  631. return (error);
  632. }
  633. if (confdb_inst->standalone) {
  634. error = CS_OK;
  635. if (confdb_sa_key_get(parent_object_handle,
  636. key_name, key_name_len,
  637. value, value_len))
  638. error = CS_ERR_ACCESS;
  639. goto error_exit;
  640. }
  641. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  642. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  643. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  644. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  645. req_lib_confdb_key_get.key_name.length = key_name_len;
  646. iov.iov_base = (char *)&req_lib_confdb_key_get;
  647. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  648. error = coroipcc_msg_send_reply_receive (
  649. confdb_inst->handle,
  650. &iov,
  651. 1,
  652. &res_lib_confdb_key_get,
  653. sizeof (struct res_lib_confdb_key_get));
  654. if (error != CS_OK) {
  655. goto error_exit;
  656. }
  657. error = res_lib_confdb_key_get.header.error;
  658. if (error == CS_OK) {
  659. *value_len = res_lib_confdb_key_get.value.length;
  660. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  661. }
  662. error_exit:
  663. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  664. return (error);
  665. }
  666. cs_error_t confdb_key_increment (
  667. confdb_handle_t handle,
  668. hdb_handle_t parent_object_handle,
  669. const void *key_name,
  670. size_t key_name_len,
  671. unsigned int *value)
  672. {
  673. cs_error_t error;
  674. struct confdb_inst *confdb_inst;
  675. struct iovec iov;
  676. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  677. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  678. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  679. if (error != CS_OK) {
  680. return (error);
  681. }
  682. if (confdb_inst->standalone) {
  683. error = CS_OK;
  684. if (confdb_sa_key_increment(parent_object_handle,
  685. key_name, key_name_len,
  686. value))
  687. error = CS_ERR_ACCESS;
  688. goto error_exit;
  689. }
  690. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  691. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  692. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  693. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  694. req_lib_confdb_key_get.key_name.length = key_name_len;
  695. iov.iov_base = (char *)&req_lib_confdb_key_get;
  696. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  697. error = coroipcc_msg_send_reply_receive (
  698. confdb_inst->handle,
  699. &iov,
  700. 1,
  701. &res_lib_confdb_key_incdec,
  702. sizeof (struct res_lib_confdb_key_incdec));
  703. if (error != CS_OK) {
  704. goto error_exit;
  705. }
  706. error = res_lib_confdb_key_incdec.header.error;
  707. if (error == CS_OK) {
  708. *value = res_lib_confdb_key_incdec.value;
  709. }
  710. error_exit:
  711. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  712. return (error);
  713. }
  714. cs_error_t confdb_key_decrement (
  715. confdb_handle_t handle,
  716. hdb_handle_t parent_object_handle,
  717. const void *key_name,
  718. size_t key_name_len,
  719. unsigned int *value)
  720. {
  721. cs_error_t error;
  722. struct confdb_inst *confdb_inst;
  723. struct iovec iov;
  724. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  725. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  726. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  727. if (error != CS_OK) {
  728. return (error);
  729. }
  730. if (confdb_inst->standalone) {
  731. error = CS_OK;
  732. if (confdb_sa_key_decrement(parent_object_handle,
  733. key_name, key_name_len,
  734. value))
  735. error = CS_ERR_ACCESS;
  736. goto error_exit;
  737. }
  738. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  739. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  740. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  741. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  742. req_lib_confdb_key_get.key_name.length = key_name_len;
  743. iov.iov_base = (char *)&req_lib_confdb_key_get;
  744. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  745. error = coroipcc_msg_send_reply_receive (
  746. confdb_inst->handle,
  747. &iov,
  748. 1,
  749. &res_lib_confdb_key_incdec,
  750. sizeof (struct res_lib_confdb_key_incdec));
  751. if (error != CS_OK) {
  752. goto error_exit;
  753. }
  754. error = res_lib_confdb_key_incdec.header.error;
  755. if (error == CS_OK) {
  756. *value = res_lib_confdb_key_incdec.value;
  757. }
  758. error_exit:
  759. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  760. return (error);
  761. }
  762. cs_error_t confdb_key_replace (
  763. confdb_handle_t handle,
  764. hdb_handle_t parent_object_handle,
  765. const void *key_name,
  766. size_t key_name_len,
  767. const void *old_value,
  768. size_t old_value_len,
  769. const void *new_value,
  770. size_t new_value_len)
  771. {
  772. cs_error_t error;
  773. struct confdb_inst *confdb_inst;
  774. struct iovec iov;
  775. struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
  776. coroipc_response_header_t res;
  777. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  778. if (error != CS_OK) {
  779. return (error);
  780. }
  781. if (confdb_inst->standalone) {
  782. error = CS_OK;
  783. if (confdb_sa_key_replace(parent_object_handle,
  784. key_name, key_name_len,
  785. old_value, old_value_len,
  786. new_value, new_value_len))
  787. error = CS_ERR_ACCESS;
  788. goto error_exit;
  789. }
  790. req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
  791. req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
  792. req_lib_confdb_key_replace.object_handle = parent_object_handle;
  793. memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
  794. req_lib_confdb_key_replace.key_name.length = key_name_len;
  795. memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
  796. req_lib_confdb_key_replace.old_value.length = old_value_len;
  797. memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
  798. req_lib_confdb_key_replace.new_value.length = new_value_len;
  799. iov.iov_base = (char *)&req_lib_confdb_key_replace;
  800. iov.iov_len = sizeof (struct req_lib_confdb_key_replace);
  801. error = coroipcc_msg_send_reply_receive (
  802. confdb_inst->handle,
  803. &iov,
  804. 1,
  805. &res,
  806. sizeof (res));
  807. if (error != CS_OK) {
  808. goto error_exit;
  809. }
  810. error = res.error;
  811. error_exit:
  812. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  813. return (error);
  814. }
  815. cs_error_t confdb_object_iter_start (
  816. confdb_handle_t handle,
  817. hdb_handle_t object_handle)
  818. {
  819. struct confdb_inst *confdb_inst;
  820. cs_error_t error = CS_OK;
  821. struct iter_context *context;
  822. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  823. if (error != CS_OK) {
  824. return (error);
  825. }
  826. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  827. if (!context) {
  828. context = malloc(sizeof(struct iter_context));
  829. if (!context) {
  830. error = CS_ERR_NO_MEMORY;
  831. goto ret;
  832. }
  833. context->parent_object_handle = object_handle;
  834. context->find_handle = 0;
  835. list_add(&context->list, &confdb_inst->object_iter_head);
  836. }
  837. /* Start a new find context */
  838. if (context->find_handle) {
  839. (void)do_find_destroy(confdb_inst, context->find_handle);
  840. context->find_handle = 0;
  841. }
  842. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  843. ret:
  844. return error;
  845. }
  846. cs_error_t confdb_key_iter_start (
  847. confdb_handle_t handle,
  848. hdb_handle_t object_handle)
  849. {
  850. struct confdb_inst *confdb_inst;
  851. cs_error_t error = CS_OK;
  852. struct iter_context *context;
  853. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  854. if (error != CS_OK) {
  855. return (error);
  856. }
  857. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  858. if (!context) {
  859. context = malloc(sizeof(struct iter_context));
  860. if (!context) {
  861. error = CS_ERR_NO_MEMORY;
  862. goto ret;
  863. }
  864. context->parent_object_handle = object_handle;
  865. list_add(&context->list, &confdb_inst->key_iter_head);
  866. }
  867. context->find_handle = 0;
  868. context->next_entry = 0;
  869. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  870. ret:
  871. return error;
  872. }
  873. cs_error_t confdb_object_find_start (
  874. confdb_handle_t handle,
  875. hdb_handle_t parent_object_handle)
  876. {
  877. struct confdb_inst *confdb_inst;
  878. cs_error_t error = CS_OK;
  879. struct iter_context *context;
  880. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  881. if (error != CS_OK) {
  882. return (error);
  883. }
  884. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  885. if (!context) {
  886. context = malloc(sizeof(struct iter_context));
  887. if (!context) {
  888. error = CS_ERR_NO_MEMORY;
  889. goto ret;
  890. }
  891. context->find_handle = 0;
  892. context->parent_object_handle = parent_object_handle;
  893. list_add(&context->list, &confdb_inst->object_find_head);
  894. }
  895. /* Start a new find context */
  896. if (context->find_handle) {
  897. (void)do_find_destroy(confdb_inst, context->find_handle);
  898. context->find_handle = 0;
  899. }
  900. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  901. ret:
  902. return error;
  903. }
  904. cs_error_t confdb_object_find (
  905. confdb_handle_t handle,
  906. hdb_handle_t parent_object_handle,
  907. const void *object_name,
  908. size_t object_name_len,
  909. hdb_handle_t *object_handle)
  910. {
  911. cs_error_t error;
  912. struct confdb_inst *confdb_inst;
  913. struct iovec iov;
  914. struct iter_context *context;
  915. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  916. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  917. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  918. if (error != CS_OK) {
  919. return (error);
  920. }
  921. /* You MUST call confdb_object_find_start first */
  922. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  923. if (!context) {
  924. error = CS_ERR_CONTEXT_NOT_FOUND;
  925. goto error_exit;
  926. }
  927. if (confdb_inst->standalone) {
  928. error = CS_OK;
  929. if (confdb_sa_object_find(parent_object_handle,
  930. &context->find_handle,
  931. object_handle,
  932. object_name, object_name_len))
  933. error = CS_ERR_ACCESS;
  934. goto error_exit;
  935. }
  936. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  937. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  938. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  939. req_lib_confdb_object_find.find_handle = context->find_handle;
  940. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  941. req_lib_confdb_object_find.object_name.length = object_name_len;
  942. iov.iov_base = (char *)&req_lib_confdb_object_find;
  943. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  944. error = coroipcc_msg_send_reply_receive (
  945. confdb_inst->handle,
  946. &iov,
  947. 1,
  948. &res_lib_confdb_object_find,
  949. sizeof (struct res_lib_confdb_object_find));
  950. if (error != CS_OK) {
  951. goto error_exit;
  952. }
  953. error = res_lib_confdb_object_find.header.error;
  954. *object_handle = res_lib_confdb_object_find.object_handle;
  955. context->find_handle = res_lib_confdb_object_find.find_handle;
  956. error_exit:
  957. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  958. return (error);
  959. }
  960. cs_error_t confdb_object_iter (
  961. confdb_handle_t handle,
  962. hdb_handle_t parent_object_handle,
  963. hdb_handle_t *object_handle,
  964. void *object_name,
  965. size_t *object_name_len)
  966. {
  967. cs_error_t error;
  968. struct confdb_inst *confdb_inst;
  969. struct iovec iov;
  970. struct iter_context *context;
  971. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  972. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  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. /* You MUST call confdb_object_iter_start first */
  978. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  979. if (!context) {
  980. error = CS_ERR_CONTEXT_NOT_FOUND;
  981. goto error_exit;
  982. }
  983. if (confdb_inst->standalone) {
  984. error = CS_OK;
  985. *object_name_len = 0;
  986. if (confdb_sa_object_iter(parent_object_handle,
  987. &context->find_handle,
  988. object_handle,
  989. NULL, 0,
  990. object_name, object_name_len))
  991. error = CS_ERR_ACCESS;
  992. goto sa_exit;
  993. }
  994. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  995. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  996. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  997. req_lib_confdb_object_iter.find_handle = context->find_handle;
  998. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  999. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1000. error = coroipcc_msg_send_reply_receive (
  1001. confdb_inst->handle,
  1002. &iov,
  1003. 1,
  1004. &res_lib_confdb_object_iter,
  1005. sizeof (struct res_lib_confdb_object_iter));
  1006. if (error != CS_OK) {
  1007. goto error_exit;
  1008. }
  1009. error = res_lib_confdb_object_iter.header.error;
  1010. if (error == CS_OK) {
  1011. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1012. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1013. *object_handle = res_lib_confdb_object_iter.object_handle;
  1014. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1015. }
  1016. sa_exit:
  1017. error_exit:
  1018. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1019. return (error);
  1020. }
  1021. cs_error_t confdb_key_iter (
  1022. confdb_handle_t handle,
  1023. hdb_handle_t parent_object_handle,
  1024. void *key_name,
  1025. size_t *key_name_len,
  1026. void *value,
  1027. size_t *value_len)
  1028. {
  1029. cs_error_t error;
  1030. struct confdb_inst *confdb_inst;
  1031. struct iovec iov;
  1032. struct iter_context *context;
  1033. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1034. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1035. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1036. if (error != CS_OK) {
  1037. return (error);
  1038. }
  1039. /* You MUST call confdb_key_iter_start first */
  1040. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1041. if (!context) {
  1042. error = CS_ERR_CONTEXT_NOT_FOUND;
  1043. goto error_exit;
  1044. }
  1045. if (confdb_inst->standalone) {
  1046. error = CS_OK;
  1047. if (confdb_sa_key_iter(parent_object_handle,
  1048. context->next_entry,
  1049. key_name, key_name_len,
  1050. value, value_len))
  1051. error = CS_ERR_ACCESS;
  1052. goto sa_exit;
  1053. }
  1054. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1055. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1056. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1057. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1058. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1059. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1060. error = coroipcc_msg_send_reply_receive (
  1061. confdb_inst->handle,
  1062. &iov,
  1063. 1,
  1064. &res_lib_confdb_key_iter,
  1065. sizeof (struct res_lib_confdb_key_iter));
  1066. if (error != CS_OK) {
  1067. goto error_exit;
  1068. }
  1069. error = res_lib_confdb_key_iter.header.error;
  1070. if (error == CS_OK) {
  1071. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1072. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1073. *value_len = res_lib_confdb_key_iter.value.length;
  1074. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1075. }
  1076. sa_exit:
  1077. context->next_entry++;
  1078. error_exit:
  1079. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1080. return (error);
  1081. }
  1082. cs_error_t confdb_write (
  1083. confdb_handle_t handle,
  1084. char *error_text,
  1085. size_t errbuf_len)
  1086. {
  1087. cs_error_t error;
  1088. struct confdb_inst *confdb_inst;
  1089. struct iovec iov;
  1090. coroipc_request_header_t req;
  1091. struct res_lib_confdb_write res_lib_confdb_write;
  1092. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1093. if (error != CS_OK) {
  1094. /* FIXME: set error_text */
  1095. return (error);
  1096. }
  1097. if (confdb_inst->standalone) {
  1098. error = CS_OK;
  1099. if (confdb_sa_write(error_text, errbuf_len))
  1100. error = CS_ERR_ACCESS;
  1101. goto error_exit;
  1102. }
  1103. req.size = sizeof (coroipc_request_header_t);
  1104. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1105. iov.iov_base = (char *)&req;
  1106. iov.iov_len = sizeof (coroipc_request_header_t);
  1107. error = coroipcc_msg_send_reply_receive (
  1108. confdb_inst->handle,
  1109. &iov,
  1110. 1,
  1111. &res_lib_confdb_write,
  1112. sizeof (struct res_lib_confdb_write));
  1113. if (error != CS_OK) {
  1114. /* FIXME: set error_text */
  1115. goto error_exit;
  1116. }
  1117. error = res_lib_confdb_write.header.error;
  1118. if (res_lib_confdb_write.error.length) {
  1119. memcpy(error_text, res_lib_confdb_write.error.value,
  1120. MIN(res_lib_confdb_write.error.length,errbuf_len));
  1121. error_text[errbuf_len-1] = '\0';
  1122. }
  1123. error_exit:
  1124. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1125. return (error);
  1126. }
  1127. cs_error_t confdb_reload (
  1128. confdb_handle_t handle,
  1129. int flush,
  1130. char *error_text,
  1131. size_t errbuf_len)
  1132. {
  1133. cs_error_t error;
  1134. struct confdb_inst *confdb_inst;
  1135. struct iovec iov;
  1136. struct res_lib_confdb_reload res_lib_confdb_reload;
  1137. struct req_lib_confdb_reload req_lib_confdb_reload;
  1138. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1139. if (error != CS_OK) {
  1140. /* FIXME: set error_text */
  1141. return (error);
  1142. }
  1143. if (confdb_inst->standalone) {
  1144. error = CS_OK;
  1145. if (confdb_sa_reload(flush, error_text, errbuf_len))
  1146. error = CS_ERR_ACCESS;
  1147. goto error_exit;
  1148. }
  1149. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1150. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1151. req_lib_confdb_reload.flush = flush;
  1152. iov.iov_base = (char *)&req_lib_confdb_reload;
  1153. iov.iov_len = sizeof (req_lib_confdb_reload);
  1154. error = coroipcc_msg_send_reply_receive (
  1155. confdb_inst->handle,
  1156. &iov,
  1157. 1,
  1158. &res_lib_confdb_reload,
  1159. sizeof (struct res_lib_confdb_reload));
  1160. if (error != CS_OK) {
  1161. /* FIXME: set error_text */
  1162. goto error_exit;
  1163. }
  1164. error = res_lib_confdb_reload.header.error;
  1165. if(res_lib_confdb_reload.error.length) {
  1166. memcpy(error_text, res_lib_confdb_reload.error.value,
  1167. MIN(res_lib_confdb_reload.error.length,errbuf_len));
  1168. error_text[errbuf_len-1] = '\0';
  1169. }
  1170. error_exit:
  1171. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1172. return (error);
  1173. }
  1174. cs_error_t confdb_track_changes (
  1175. confdb_handle_t handle,
  1176. hdb_handle_t object_handle,
  1177. unsigned int flags)
  1178. {
  1179. cs_error_t error;
  1180. struct confdb_inst *confdb_inst;
  1181. struct iovec iov;
  1182. struct req_lib_confdb_object_track_start req;
  1183. coroipc_response_header_t res;
  1184. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1185. if (error != CS_OK) {
  1186. return (error);
  1187. }
  1188. if (confdb_inst->standalone) {
  1189. error = CS_ERR_NOT_SUPPORTED;
  1190. goto error_exit;
  1191. }
  1192. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1193. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1194. req.object_handle = object_handle;
  1195. req.flags = flags;
  1196. iov.iov_base = (char *)&req;
  1197. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1198. error = coroipcc_msg_send_reply_receive (
  1199. confdb_inst->handle,
  1200. &iov,
  1201. 1,
  1202. &res,
  1203. sizeof (coroipc_response_header_t));
  1204. if (error != CS_OK) {
  1205. goto error_exit;
  1206. }
  1207. error = res.error;
  1208. error_exit:
  1209. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1210. return (error);
  1211. }
  1212. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1213. {
  1214. cs_error_t error;
  1215. struct confdb_inst *confdb_inst;
  1216. struct iovec iov;
  1217. coroipc_request_header_t req;
  1218. coroipc_response_header_t res;
  1219. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1220. if (error != CS_OK) {
  1221. return (error);
  1222. }
  1223. if (confdb_inst->standalone) {
  1224. error = CS_ERR_NOT_SUPPORTED;
  1225. goto error_exit;
  1226. }
  1227. req.size = sizeof (coroipc_request_header_t);
  1228. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1229. iov.iov_base = (char *)&req;
  1230. iov.iov_len = sizeof (coroipc_request_header_t);
  1231. error = coroipcc_msg_send_reply_receive (
  1232. confdb_inst->handle,
  1233. &iov,
  1234. 1,
  1235. &res,
  1236. sizeof (coroipc_response_header_t));
  1237. if (error != CS_OK) {
  1238. goto error_exit;
  1239. }
  1240. error = res.error;
  1241. error_exit:
  1242. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1243. return (error);
  1244. }