confdb.c 45 KB

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