confdb.c 40 KB

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