confdb.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  1. /*
  2. * Copyright (c) 2008-2009 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * Provides access to data in the corosync object database
  36. */
  37. #include <config.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <unistd.h>
  41. #include <pthread.h>
  42. #include <sys/types.h>
  43. #include <errno.h>
  44. #include <corosync/corotypes.h>
  45. #include <corosync/coroipc_types.h>
  46. #include <corosync/coroipcc.h>
  47. #include <corosync/corodefs.h>
  48. #include <corosync/hdb.h>
  49. #include <corosync/list.h>
  50. #include <corosync/confdb.h>
  51. #include <corosync/ipc_confdb.h>
  52. #include "util.h"
  53. #include "sa-confdb.h"
  54. #undef MIN
  55. #define MIN(x,y) ((x) < (y) ? (x) : (y))
  56. /* Hold the information for iterators so that
  57. callers can do recursive tree traversals.
  58. each object_handle can have its own iterator */
  59. struct iter_context {
  60. struct list_head list;
  61. hdb_handle_t parent_object_handle;
  62. hdb_handle_t find_handle;
  63. hdb_handle_t next_entry;
  64. };
  65. struct confdb_inst {
  66. hdb_handle_t handle;
  67. int finalize;
  68. int standalone;
  69. confdb_callbacks_t callbacks;
  70. const void *context;
  71. struct list_head object_find_head;
  72. struct list_head object_iter_head;
  73. struct list_head key_iter_head;
  74. };
  75. DECLARE_HDB_DATABASE(confdb_handle_t_db,NULL);
  76. static cs_error_t do_find_destroy(struct confdb_inst *confdb_inst, hdb_handle_t find_handle);
  77. /* Safely tidy one iterator context list */
  78. static void free_context_list(struct confdb_inst *confdb_inst, struct list_head *list)
  79. {
  80. struct iter_context *context;
  81. struct list_head *iter, *tmp;
  82. for (iter = list->next, tmp = iter->next;
  83. iter != list; iter = tmp, tmp = iter->next) {
  84. context = list_entry (iter, struct iter_context, list);
  85. (void)do_find_destroy(confdb_inst, context->find_handle);
  86. free(context);
  87. }
  88. }
  89. static struct iter_context *find_iter_context(struct list_head *list, hdb_handle_t object_handle)
  90. {
  91. struct iter_context *context;
  92. struct list_head *iter;
  93. for (iter = list->next;
  94. iter != list; iter = iter->next) {
  95. context = list_entry (iter, struct iter_context, list);
  96. if (context->parent_object_handle == object_handle)
  97. return context;
  98. }
  99. return NULL;
  100. }
  101. /**
  102. * @defgroup confdb_corosync
  103. * @ingroup corosync
  104. *
  105. * @{
  106. */
  107. cs_error_t confdb_initialize (
  108. confdb_handle_t *handle,
  109. confdb_callbacks_t *callbacks)
  110. {
  111. cs_error_t error;
  112. struct confdb_inst *confdb_inst;
  113. error = hdb_error_to_cs(hdb_handle_create (&confdb_handle_t_db, sizeof (struct confdb_inst), handle));
  114. if (error != CS_OK) {
  115. goto error_no_destroy;
  116. }
  117. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, *handle, (void *)&confdb_inst));
  118. if (error != CS_OK) {
  119. goto error_destroy;
  120. }
  121. if (getenv("COROSYNC_DEFAULT_CONFIG_IFACE")) {
  122. error = confdb_sa_init();
  123. confdb_inst->standalone = 1;
  124. }
  125. else {
  126. error = coroipcc_service_connect (
  127. COROSYNC_SOCKET_NAME,
  128. CONFDB_SERVICE,
  129. IPC_REQUEST_SIZE,
  130. IPC_RESPONSE_SIZE,
  131. IPC_DISPATCH_SIZE,
  132. &confdb_inst->handle);
  133. }
  134. if (error != CS_OK)
  135. goto error_put_destroy;
  136. memcpy (&confdb_inst->callbacks, callbacks, sizeof (confdb_callbacks_t));
  137. list_init (&confdb_inst->object_find_head);
  138. list_init (&confdb_inst->object_iter_head);
  139. list_init (&confdb_inst->key_iter_head);
  140. (void)hdb_handle_put (&confdb_handle_t_db, *handle);
  141. return (CS_OK);
  142. error_put_destroy:
  143. (void)hdb_handle_put (&confdb_handle_t_db, *handle);
  144. error_destroy:
  145. (void)hdb_handle_destroy (&confdb_handle_t_db, *handle);
  146. error_no_destroy:
  147. return (error);
  148. }
  149. cs_error_t confdb_finalize (
  150. confdb_handle_t handle)
  151. {
  152. struct confdb_inst *confdb_inst;
  153. cs_error_t error;
  154. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  155. if (error != CS_OK) {
  156. return (error);
  157. }
  158. /*
  159. * Another thread has already started finalizing
  160. */
  161. if (confdb_inst->finalize) {
  162. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  163. return (CS_ERR_BAD_HANDLE);
  164. }
  165. confdb_inst->finalize = 1;
  166. /* Free saved context handles */
  167. free_context_list(confdb_inst, &confdb_inst->object_find_head);
  168. free_context_list(confdb_inst, &confdb_inst->object_iter_head);
  169. free_context_list(confdb_inst, &confdb_inst->key_iter_head);
  170. if (!confdb_inst->standalone) {
  171. coroipcc_service_disconnect (confdb_inst->handle);
  172. }
  173. (void)hdb_handle_destroy (&confdb_handle_t_db, handle);
  174. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  175. return (CS_OK);
  176. }
  177. cs_error_t confdb_fd_get (
  178. confdb_handle_t handle,
  179. int *fd)
  180. {
  181. cs_error_t error;
  182. struct confdb_inst *confdb_inst;
  183. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  184. if (error != CS_OK) {
  185. return (error);
  186. }
  187. error = coroipcc_fd_get (confdb_inst->handle, fd);
  188. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  189. return (error);
  190. }
  191. cs_error_t confdb_context_get (
  192. confdb_handle_t handle,
  193. const void **context)
  194. {
  195. cs_error_t error;
  196. struct confdb_inst *confdb_inst;
  197. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  198. if (error != CS_OK) {
  199. return (error);
  200. }
  201. *context = confdb_inst->context;
  202. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  203. return (CS_OK);
  204. }
  205. cs_error_t confdb_context_set (
  206. confdb_handle_t handle,
  207. const void *context)
  208. {
  209. cs_error_t error;
  210. struct confdb_inst *confdb_inst;
  211. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  212. if (error != CS_OK) {
  213. return (error);
  214. }
  215. confdb_inst->context = context;
  216. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  217. return (CS_OK);
  218. }
  219. cs_error_t confdb_dispatch (
  220. confdb_handle_t handle,
  221. cs_dispatch_flags_t dispatch_types)
  222. {
  223. int timeout = -1;
  224. cs_error_t error;
  225. int cont = 1; /* always continue do loop except when set to 0 */
  226. struct confdb_inst *confdb_inst;
  227. confdb_callbacks_t callbacks;
  228. struct res_lib_confdb_key_change_callback *res_key_changed_pt;
  229. struct res_lib_confdb_object_create_callback *res_object_created_pt;
  230. struct res_lib_confdb_object_destroy_callback *res_object_destroyed_pt;
  231. coroipc_response_header_t *dispatch_data;
  232. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  233. if (error != CS_OK) {
  234. return (error);
  235. }
  236. if (confdb_inst->standalone) {
  237. error = CS_ERR_NOT_SUPPORTED;
  238. goto error_put;
  239. }
  240. /*
  241. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  242. * wait indefinately for SA_DISPATCH_BLOCKING
  243. */
  244. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  245. timeout = 0;
  246. }
  247. do {
  248. error = coroipcc_dispatch_get (
  249. confdb_inst->handle,
  250. (void **)&dispatch_data,
  251. timeout);
  252. if (error == CS_ERR_BAD_HANDLE) {
  253. error = CS_OK;
  254. goto error_put;
  255. }
  256. if (error != CS_OK) {
  257. goto error_put;
  258. }
  259. if (dispatch_data == NULL) {
  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. /*
  267. * Make copy of callbacks, message data, unlock instance, and call callback
  268. * A risk of this dispatch method is that the callback routines may
  269. * operate at the same time that confdbFinalize has been called.
  270. */
  271. memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
  272. /*
  273. * Dispatch incoming message
  274. */
  275. switch (dispatch_data->id) {
  276. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
  277. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
  278. callbacks.confdb_key_change_notify_fn(handle,
  279. res_key_changed_pt->change_type,
  280. res_key_changed_pt->object_handle,
  281. res_key_changed_pt->parent_object_handle,
  282. res_key_changed_pt->object_name.value,
  283. res_key_changed_pt->object_name.length,
  284. res_key_changed_pt->key_name.value,
  285. res_key_changed_pt->key_name.length,
  286. res_key_changed_pt->key_value.value,
  287. res_key_changed_pt->key_value.length);
  288. break;
  289. case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
  290. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)dispatch_data;
  291. callbacks.confdb_object_create_change_notify_fn(handle,
  292. res_object_created_pt->object_handle,
  293. res_object_created_pt->parent_object_handle,
  294. res_object_created_pt->name.value,
  295. res_object_created_pt->name.length);
  296. break;
  297. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  298. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)dispatch_data;
  299. callbacks.confdb_object_delete_change_notify_fn(handle,
  300. res_object_destroyed_pt->parent_object_handle,
  301. res_object_destroyed_pt->name.value,
  302. res_object_destroyed_pt->name.length);
  303. break;
  304. default:
  305. coroipcc_dispatch_put (confdb_inst->handle);
  306. error = CS_ERR_LIBRARY;
  307. goto error_noput;
  308. break;
  309. }
  310. coroipcc_dispatch_put (confdb_inst->handle);
  311. /*
  312. * Determine if more messages should be processed
  313. * */
  314. switch (dispatch_types) {
  315. case CONFDB_DISPATCH_ONE:
  316. cont = 0;
  317. break;
  318. case CONFDB_DISPATCH_ALL:
  319. break;
  320. case CONFDB_DISPATCH_BLOCKING:
  321. break;
  322. }
  323. } while (cont);
  324. error_put:
  325. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  326. error_noput:
  327. return (error);
  328. }
  329. cs_error_t confdb_object_create (
  330. confdb_handle_t handle,
  331. hdb_handle_t parent_object_handle,
  332. const void *object_name,
  333. size_t object_name_len,
  334. hdb_handle_t *object_handle)
  335. {
  336. cs_error_t error;
  337. struct confdb_inst *confdb_inst;
  338. struct iovec iov;
  339. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  340. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  341. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  342. if (error != CS_OK) {
  343. return (error);
  344. }
  345. if (confdb_inst->standalone) {
  346. error = CS_OK;
  347. if (confdb_sa_object_create(parent_object_handle,
  348. object_name, object_name_len,
  349. object_handle))
  350. error = CS_ERR_ACCESS;
  351. goto error_exit;
  352. }
  353. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  354. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  355. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  356. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  357. req_lib_confdb_object_create.object_name.length = object_name_len;
  358. iov.iov_base = (char *)&req_lib_confdb_object_create;
  359. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  360. error = coroipcc_msg_send_reply_receive (
  361. confdb_inst->handle,
  362. &iov,
  363. 1,
  364. &res_lib_confdb_object_create,
  365. sizeof (struct res_lib_confdb_object_create));
  366. if (error != CS_OK) {
  367. goto error_exit;
  368. }
  369. error = res_lib_confdb_object_create.header.error;
  370. *object_handle = res_lib_confdb_object_create.object_handle;
  371. error_exit:
  372. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  373. return (error);
  374. }
  375. cs_error_t confdb_object_destroy (
  376. confdb_handle_t handle,
  377. hdb_handle_t object_handle)
  378. {
  379. cs_error_t error;
  380. struct confdb_inst *confdb_inst;
  381. struct iovec iov;
  382. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  383. coroipc_response_header_t res;
  384. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  385. if (error != CS_OK) {
  386. return (error);
  387. }
  388. if (confdb_inst->standalone) {
  389. error = CS_OK;
  390. if (confdb_sa_object_destroy(object_handle))
  391. error = CS_ERR_ACCESS;
  392. goto error_exit;
  393. }
  394. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  395. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  396. req_lib_confdb_object_destroy.object_handle = object_handle;
  397. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  398. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  399. error = coroipcc_msg_send_reply_receive (
  400. confdb_inst->handle,
  401. &iov,
  402. 1,
  403. &res,
  404. sizeof (coroipc_response_header_t));
  405. if (error != CS_OK) {
  406. goto error_exit;
  407. }
  408. error = res.error;
  409. error_exit:
  410. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  411. return (error);
  412. }
  413. cs_error_t confdb_object_parent_get (
  414. confdb_handle_t handle,
  415. hdb_handle_t object_handle,
  416. hdb_handle_t *parent_object_handle)
  417. {
  418. cs_error_t error;
  419. struct confdb_inst *confdb_inst;
  420. struct iovec iov;
  421. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  422. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  423. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  424. if (error != CS_OK) {
  425. return (error);
  426. }
  427. if (confdb_inst->standalone) {
  428. error = CS_OK;
  429. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  430. error = CS_ERR_ACCESS;
  431. goto error_exit;
  432. }
  433. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  434. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  435. req_lib_confdb_object_parent_get.object_handle = object_handle;
  436. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  437. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  438. error = coroipcc_msg_send_reply_receive (
  439. confdb_inst->handle,
  440. &iov,
  441. 1,
  442. &res_lib_confdb_object_parent_get,
  443. sizeof (struct res_lib_confdb_object_parent_get));
  444. if (error != CS_OK) {
  445. goto error_exit;
  446. }
  447. error = res_lib_confdb_object_parent_get.header.error;
  448. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  449. error_exit:
  450. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  451. return (error);
  452. }
  453. static cs_error_t do_find_destroy(
  454. struct confdb_inst *confdb_inst,
  455. hdb_handle_t find_handle)
  456. {
  457. cs_error_t error;
  458. struct iovec iov;
  459. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  460. coroipc_response_header_t res;
  461. if (!find_handle)
  462. return CS_OK;
  463. if (confdb_inst->standalone) {
  464. error = CS_OK;
  465. if (confdb_sa_find_destroy(find_handle))
  466. error = CS_ERR_ACCESS;
  467. goto error_exit;
  468. }
  469. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  470. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  471. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  472. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  473. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  474. error = coroipcc_msg_send_reply_receive (
  475. confdb_inst->handle,
  476. &iov,
  477. 1,
  478. &res,
  479. sizeof (coroipc_response_header_t));
  480. if (error != CS_OK) {
  481. goto error_exit;
  482. }
  483. error = res.error;
  484. error_exit:
  485. return (error);
  486. }
  487. cs_error_t confdb_object_find_destroy(
  488. confdb_handle_t handle,
  489. hdb_handle_t parent_object_handle)
  490. {
  491. struct iter_context *context;
  492. cs_error_t error;
  493. struct confdb_inst *confdb_inst;
  494. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  495. if (error != CS_OK) {
  496. return (error);
  497. }
  498. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  499. error = do_find_destroy(confdb_inst, context->find_handle);
  500. if (error == CS_OK) {
  501. list_del(&context->list);
  502. free(context);
  503. }
  504. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  505. return error;
  506. }
  507. cs_error_t confdb_object_iter_destroy(
  508. confdb_handle_t handle,
  509. hdb_handle_t parent_object_handle)
  510. {
  511. struct iter_context *context;
  512. cs_error_t error;
  513. struct confdb_inst *confdb_inst;
  514. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  515. if (error != CS_OK) {
  516. return (error);
  517. }
  518. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  519. error = do_find_destroy(confdb_inst, context->find_handle);
  520. if (error == CS_OK) {
  521. list_del(&context->list);
  522. free(context);
  523. }
  524. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  525. return error;
  526. }
  527. cs_error_t confdb_key_create (
  528. confdb_handle_t handle,
  529. hdb_handle_t parent_object_handle,
  530. const void *key_name,
  531. size_t key_name_len,
  532. const void *value,
  533. size_t value_len)
  534. {
  535. cs_error_t error;
  536. struct confdb_inst *confdb_inst;
  537. struct iovec iov;
  538. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  539. coroipc_response_header_t res;
  540. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  541. if (error != CS_OK) {
  542. return (error);
  543. }
  544. if (confdb_inst->standalone) {
  545. error = CS_OK;
  546. if (confdb_sa_key_create(parent_object_handle,
  547. key_name, key_name_len,
  548. value, value_len))
  549. error = CS_ERR_ACCESS;
  550. goto error_exit;
  551. }
  552. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  553. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  554. req_lib_confdb_key_create.object_handle = parent_object_handle;
  555. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  556. req_lib_confdb_key_create.key_name.length = key_name_len;
  557. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  558. req_lib_confdb_key_create.value.length = value_len;
  559. iov.iov_base = (char *)&req_lib_confdb_key_create;
  560. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  561. error = coroipcc_msg_send_reply_receive (
  562. confdb_inst->handle,
  563. &iov,
  564. 1,
  565. &res,
  566. sizeof (res));
  567. if (error != CS_OK) {
  568. goto error_exit;
  569. }
  570. error = res.error;
  571. error_exit:
  572. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  573. return (error);
  574. }
  575. cs_error_t confdb_key_delete (
  576. confdb_handle_t handle,
  577. hdb_handle_t parent_object_handle,
  578. const void *key_name,
  579. size_t key_name_len,
  580. const void *value,
  581. size_t value_len)
  582. {
  583. cs_error_t error;
  584. struct confdb_inst *confdb_inst;
  585. struct iovec iov;
  586. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  587. coroipc_response_header_t res;
  588. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  589. if (error != CS_OK) {
  590. return (error);
  591. }
  592. if (confdb_inst->standalone) {
  593. error = CS_OK;
  594. if (confdb_sa_key_delete(parent_object_handle,
  595. key_name, key_name_len,
  596. value, value_len))
  597. error = CS_ERR_ACCESS;
  598. goto error_exit;
  599. }
  600. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  601. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  602. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  603. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  604. req_lib_confdb_key_delete.key_name.length = key_name_len;
  605. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  606. req_lib_confdb_key_delete.value.length = value_len;
  607. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  608. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  609. error = coroipcc_msg_send_reply_receive (
  610. confdb_inst->handle,
  611. &iov,
  612. 1,
  613. &res,
  614. sizeof (res));
  615. if (error != CS_OK) {
  616. goto error_exit;
  617. }
  618. error = res.error;
  619. error_exit:
  620. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  621. return (error);
  622. }
  623. cs_error_t confdb_key_get (
  624. confdb_handle_t handle,
  625. hdb_handle_t parent_object_handle,
  626. const void *key_name,
  627. size_t key_name_len,
  628. void *value,
  629. size_t *value_len)
  630. {
  631. cs_error_t error;
  632. struct confdb_inst *confdb_inst;
  633. struct iovec iov;
  634. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  635. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  636. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  637. if (error != CS_OK) {
  638. return (error);
  639. }
  640. if (confdb_inst->standalone) {
  641. error = CS_OK;
  642. if (confdb_sa_key_get(parent_object_handle,
  643. key_name, key_name_len,
  644. value, value_len))
  645. error = CS_ERR_ACCESS;
  646. goto error_exit;
  647. }
  648. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  649. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  650. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  651. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  652. req_lib_confdb_key_get.key_name.length = key_name_len;
  653. iov.iov_base = (char *)&req_lib_confdb_key_get;
  654. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  655. error = coroipcc_msg_send_reply_receive (
  656. confdb_inst->handle,
  657. &iov,
  658. 1,
  659. &res_lib_confdb_key_get,
  660. sizeof (struct res_lib_confdb_key_get));
  661. if (error != CS_OK) {
  662. goto error_exit;
  663. }
  664. error = res_lib_confdb_key_get.header.error;
  665. if (error == CS_OK) {
  666. *value_len = res_lib_confdb_key_get.value.length;
  667. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  668. }
  669. error_exit:
  670. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  671. return (error);
  672. }
  673. cs_error_t confdb_key_increment (
  674. confdb_handle_t handle,
  675. hdb_handle_t parent_object_handle,
  676. const void *key_name,
  677. size_t key_name_len,
  678. unsigned int *value)
  679. {
  680. cs_error_t error;
  681. struct confdb_inst *confdb_inst;
  682. struct iovec iov;
  683. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  684. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  685. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  686. if (error != CS_OK) {
  687. return (error);
  688. }
  689. if (confdb_inst->standalone) {
  690. error = CS_OK;
  691. if (confdb_sa_key_increment(parent_object_handle,
  692. key_name, key_name_len,
  693. value))
  694. error = CS_ERR_ACCESS;
  695. goto error_exit;
  696. }
  697. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  698. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  699. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  700. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  701. req_lib_confdb_key_get.key_name.length = key_name_len;
  702. iov.iov_base = (char *)&req_lib_confdb_key_get;
  703. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  704. error = coroipcc_msg_send_reply_receive (
  705. confdb_inst->handle,
  706. &iov,
  707. 1,
  708. &res_lib_confdb_key_incdec,
  709. sizeof (struct res_lib_confdb_key_incdec));
  710. if (error != CS_OK) {
  711. goto error_exit;
  712. }
  713. error = res_lib_confdb_key_incdec.header.error;
  714. if (error == CS_OK) {
  715. *value = res_lib_confdb_key_incdec.value;
  716. }
  717. error_exit:
  718. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  719. return (error);
  720. }
  721. cs_error_t confdb_key_decrement (
  722. confdb_handle_t handle,
  723. hdb_handle_t parent_object_handle,
  724. const void *key_name,
  725. size_t key_name_len,
  726. unsigned int *value)
  727. {
  728. cs_error_t error;
  729. struct confdb_inst *confdb_inst;
  730. struct iovec iov;
  731. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  732. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  733. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  734. if (error != CS_OK) {
  735. return (error);
  736. }
  737. if (confdb_inst->standalone) {
  738. error = CS_OK;
  739. if (confdb_sa_key_decrement(parent_object_handle,
  740. key_name, key_name_len,
  741. value))
  742. error = CS_ERR_ACCESS;
  743. goto error_exit;
  744. }
  745. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  746. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  747. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  748. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  749. req_lib_confdb_key_get.key_name.length = key_name_len;
  750. iov.iov_base = (char *)&req_lib_confdb_key_get;
  751. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  752. error = coroipcc_msg_send_reply_receive (
  753. confdb_inst->handle,
  754. &iov,
  755. 1,
  756. &res_lib_confdb_key_incdec,
  757. sizeof (struct res_lib_confdb_key_incdec));
  758. if (error != CS_OK) {
  759. goto error_exit;
  760. }
  761. error = res_lib_confdb_key_incdec.header.error;
  762. if (error == CS_OK) {
  763. *value = res_lib_confdb_key_incdec.value;
  764. }
  765. error_exit:
  766. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  767. return (error);
  768. }
  769. cs_error_t confdb_key_replace (
  770. confdb_handle_t handle,
  771. hdb_handle_t parent_object_handle,
  772. const void *key_name,
  773. size_t key_name_len,
  774. const void *old_value,
  775. size_t old_value_len,
  776. const void *new_value,
  777. size_t new_value_len)
  778. {
  779. cs_error_t error;
  780. struct confdb_inst *confdb_inst;
  781. struct iovec iov;
  782. struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
  783. coroipc_response_header_t res;
  784. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  785. if (error != CS_OK) {
  786. return (error);
  787. }
  788. if (confdb_inst->standalone) {
  789. error = CS_OK;
  790. if (confdb_sa_key_replace(parent_object_handle,
  791. key_name, key_name_len,
  792. old_value, old_value_len,
  793. new_value, new_value_len))
  794. error = CS_ERR_ACCESS;
  795. goto error_exit;
  796. }
  797. req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
  798. req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
  799. req_lib_confdb_key_replace.object_handle = parent_object_handle;
  800. memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
  801. req_lib_confdb_key_replace.key_name.length = key_name_len;
  802. memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
  803. req_lib_confdb_key_replace.old_value.length = old_value_len;
  804. memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
  805. req_lib_confdb_key_replace.new_value.length = new_value_len;
  806. iov.iov_base = (char *)&req_lib_confdb_key_replace;
  807. iov.iov_len = sizeof (struct req_lib_confdb_key_replace);
  808. error = coroipcc_msg_send_reply_receive (
  809. confdb_inst->handle,
  810. &iov,
  811. 1,
  812. &res,
  813. sizeof (res));
  814. if (error != CS_OK) {
  815. goto error_exit;
  816. }
  817. error = res.error;
  818. error_exit:
  819. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  820. return (error);
  821. }
  822. cs_error_t confdb_object_iter_start (
  823. confdb_handle_t handle,
  824. hdb_handle_t object_handle)
  825. {
  826. struct confdb_inst *confdb_inst;
  827. cs_error_t error = CS_OK;
  828. struct iter_context *context;
  829. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  830. if (error != CS_OK) {
  831. return (error);
  832. }
  833. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  834. if (!context) {
  835. context = malloc(sizeof(struct iter_context));
  836. if (!context) {
  837. error = CS_ERR_NO_MEMORY;
  838. goto ret;
  839. }
  840. context->parent_object_handle = object_handle;
  841. context->find_handle = 0;
  842. list_add(&context->list, &confdb_inst->object_iter_head);
  843. }
  844. /* Start a new find context */
  845. if (context->find_handle) {
  846. (void)do_find_destroy(confdb_inst, context->find_handle);
  847. context->find_handle = 0;
  848. }
  849. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  850. ret:
  851. return error;
  852. }
  853. cs_error_t confdb_key_iter_start (
  854. confdb_handle_t handle,
  855. hdb_handle_t object_handle)
  856. {
  857. struct confdb_inst *confdb_inst;
  858. cs_error_t error = CS_OK;
  859. struct iter_context *context;
  860. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  861. if (error != CS_OK) {
  862. return (error);
  863. }
  864. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  865. if (!context) {
  866. context = malloc(sizeof(struct iter_context));
  867. if (!context) {
  868. error = CS_ERR_NO_MEMORY;
  869. goto ret;
  870. }
  871. context->parent_object_handle = object_handle;
  872. list_add(&context->list, &confdb_inst->key_iter_head);
  873. }
  874. context->find_handle = 0;
  875. context->next_entry = 0;
  876. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  877. ret:
  878. return error;
  879. }
  880. cs_error_t confdb_object_find_start (
  881. confdb_handle_t handle,
  882. hdb_handle_t parent_object_handle)
  883. {
  884. struct confdb_inst *confdb_inst;
  885. cs_error_t error = CS_OK;
  886. struct iter_context *context;
  887. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  888. if (error != CS_OK) {
  889. return (error);
  890. }
  891. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  892. if (!context) {
  893. context = malloc(sizeof(struct iter_context));
  894. if (!context) {
  895. error = CS_ERR_NO_MEMORY;
  896. goto ret;
  897. }
  898. context->find_handle = 0;
  899. context->parent_object_handle = parent_object_handle;
  900. list_add(&context->list, &confdb_inst->object_find_head);
  901. }
  902. /* Start a new find context */
  903. if (context->find_handle) {
  904. (void)do_find_destroy(confdb_inst, context->find_handle);
  905. context->find_handle = 0;
  906. }
  907. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  908. ret:
  909. return error;
  910. }
  911. cs_error_t confdb_object_find (
  912. confdb_handle_t handle,
  913. hdb_handle_t parent_object_handle,
  914. const void *object_name,
  915. size_t object_name_len,
  916. hdb_handle_t *object_handle)
  917. {
  918. cs_error_t error;
  919. struct confdb_inst *confdb_inst;
  920. struct iovec iov;
  921. struct iter_context *context;
  922. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  923. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  924. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  925. if (error != CS_OK) {
  926. return (error);
  927. }
  928. /* You MUST call confdb_object_find_start first */
  929. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  930. if (!context) {
  931. error = CS_ERR_CONTEXT_NOT_FOUND;
  932. goto error_exit;
  933. }
  934. if (confdb_inst->standalone) {
  935. error = CS_OK;
  936. if (confdb_sa_object_find(parent_object_handle,
  937. &context->find_handle,
  938. object_handle,
  939. object_name, object_name_len))
  940. error = CS_ERR_ACCESS;
  941. goto error_exit;
  942. }
  943. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  944. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  945. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  946. req_lib_confdb_object_find.find_handle = context->find_handle;
  947. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  948. req_lib_confdb_object_find.object_name.length = object_name_len;
  949. iov.iov_base = (char *)&req_lib_confdb_object_find;
  950. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  951. error = coroipcc_msg_send_reply_receive (
  952. confdb_inst->handle,
  953. &iov,
  954. 1,
  955. &res_lib_confdb_object_find,
  956. sizeof (struct res_lib_confdb_object_find));
  957. if (error != CS_OK) {
  958. goto error_exit;
  959. }
  960. error = res_lib_confdb_object_find.header.error;
  961. *object_handle = res_lib_confdb_object_find.object_handle;
  962. context->find_handle = res_lib_confdb_object_find.find_handle;
  963. error_exit:
  964. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  965. return (error);
  966. }
  967. cs_error_t confdb_object_iter (
  968. confdb_handle_t handle,
  969. hdb_handle_t parent_object_handle,
  970. hdb_handle_t *object_handle,
  971. void *object_name,
  972. size_t *object_name_len)
  973. {
  974. cs_error_t error;
  975. struct confdb_inst *confdb_inst;
  976. struct iovec iov;
  977. struct iter_context *context;
  978. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  979. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  980. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  981. if (error != CS_OK) {
  982. return (error);
  983. }
  984. /* You MUST call confdb_object_iter_start first */
  985. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  986. if (!context) {
  987. error = CS_ERR_CONTEXT_NOT_FOUND;
  988. goto error_exit;
  989. }
  990. if (confdb_inst->standalone) {
  991. error = CS_OK;
  992. *object_name_len = 0;
  993. if (confdb_sa_object_iter(parent_object_handle,
  994. &context->find_handle,
  995. object_handle,
  996. NULL, 0,
  997. object_name, object_name_len))
  998. error = CS_ERR_ACCESS;
  999. goto sa_exit;
  1000. }
  1001. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1002. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1003. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1004. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1005. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1006. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1007. error = coroipcc_msg_send_reply_receive (
  1008. confdb_inst->handle,
  1009. &iov,
  1010. 1,
  1011. &res_lib_confdb_object_iter,
  1012. sizeof (struct res_lib_confdb_object_iter));
  1013. if (error != CS_OK) {
  1014. goto error_exit;
  1015. }
  1016. error = res_lib_confdb_object_iter.header.error;
  1017. if (error == CS_OK) {
  1018. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1019. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1020. *object_handle = res_lib_confdb_object_iter.object_handle;
  1021. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1022. }
  1023. sa_exit:
  1024. error_exit:
  1025. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1026. return (error);
  1027. }
  1028. cs_error_t confdb_key_iter (
  1029. confdb_handle_t handle,
  1030. hdb_handle_t parent_object_handle,
  1031. void *key_name,
  1032. size_t *key_name_len,
  1033. void *value,
  1034. size_t *value_len)
  1035. {
  1036. cs_error_t error;
  1037. struct confdb_inst *confdb_inst;
  1038. struct iovec iov;
  1039. struct iter_context *context;
  1040. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1041. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1042. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1043. if (error != CS_OK) {
  1044. return (error);
  1045. }
  1046. /* You MUST call confdb_key_iter_start first */
  1047. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1048. if (!context) {
  1049. error = CS_ERR_CONTEXT_NOT_FOUND;
  1050. goto error_exit;
  1051. }
  1052. if (confdb_inst->standalone) {
  1053. error = CS_OK;
  1054. if (confdb_sa_key_iter(parent_object_handle,
  1055. context->next_entry,
  1056. key_name, key_name_len,
  1057. value, value_len))
  1058. error = CS_ERR_ACCESS;
  1059. goto sa_exit;
  1060. }
  1061. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1062. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1063. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1064. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1065. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1066. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1067. error = coroipcc_msg_send_reply_receive (
  1068. confdb_inst->handle,
  1069. &iov,
  1070. 1,
  1071. &res_lib_confdb_key_iter,
  1072. sizeof (struct res_lib_confdb_key_iter));
  1073. if (error != CS_OK) {
  1074. goto error_exit;
  1075. }
  1076. error = res_lib_confdb_key_iter.header.error;
  1077. if (error == CS_OK) {
  1078. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1079. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1080. *value_len = res_lib_confdb_key_iter.value.length;
  1081. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1082. }
  1083. sa_exit:
  1084. context->next_entry++;
  1085. error_exit:
  1086. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1087. return (error);
  1088. }
  1089. cs_error_t confdb_write (
  1090. confdb_handle_t handle,
  1091. char *error_text,
  1092. size_t errbuf_len)
  1093. {
  1094. cs_error_t error;
  1095. struct confdb_inst *confdb_inst;
  1096. struct iovec iov;
  1097. coroipc_request_header_t req;
  1098. struct res_lib_confdb_write res_lib_confdb_write;
  1099. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1100. if (error != CS_OK) {
  1101. /* FIXME: set error_text */
  1102. return (error);
  1103. }
  1104. if (confdb_inst->standalone) {
  1105. error = CS_OK;
  1106. if (confdb_sa_write(error_text, errbuf_len))
  1107. error = CS_ERR_ACCESS;
  1108. goto error_exit;
  1109. }
  1110. req.size = sizeof (coroipc_request_header_t);
  1111. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1112. iov.iov_base = (char *)&req;
  1113. iov.iov_len = sizeof (coroipc_request_header_t);
  1114. error = coroipcc_msg_send_reply_receive (
  1115. confdb_inst->handle,
  1116. &iov,
  1117. 1,
  1118. &res_lib_confdb_write,
  1119. sizeof (struct res_lib_confdb_write));
  1120. if (error != CS_OK) {
  1121. /* FIXME: set error_text */
  1122. goto error_exit;
  1123. }
  1124. error = res_lib_confdb_write.header.error;
  1125. if (res_lib_confdb_write.error.length) {
  1126. memcpy(error_text, res_lib_confdb_write.error.value,
  1127. MIN(res_lib_confdb_write.error.length,errbuf_len));
  1128. error_text[errbuf_len-1] = '\0';
  1129. }
  1130. error_exit:
  1131. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1132. return (error);
  1133. }
  1134. cs_error_t confdb_reload (
  1135. confdb_handle_t handle,
  1136. int flush,
  1137. char *error_text,
  1138. size_t errbuf_len)
  1139. {
  1140. cs_error_t error;
  1141. struct confdb_inst *confdb_inst;
  1142. struct iovec iov;
  1143. struct res_lib_confdb_reload res_lib_confdb_reload;
  1144. struct req_lib_confdb_reload req_lib_confdb_reload;
  1145. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1146. if (error != CS_OK) {
  1147. /* FIXME: set error_text */
  1148. return (error);
  1149. }
  1150. if (confdb_inst->standalone) {
  1151. error = CS_OK;
  1152. if (confdb_sa_reload(flush, error_text, errbuf_len))
  1153. error = CS_ERR_ACCESS;
  1154. goto error_exit;
  1155. }
  1156. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1157. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1158. req_lib_confdb_reload.flush = flush;
  1159. iov.iov_base = (char *)&req_lib_confdb_reload;
  1160. iov.iov_len = sizeof (req_lib_confdb_reload);
  1161. error = coroipcc_msg_send_reply_receive (
  1162. confdb_inst->handle,
  1163. &iov,
  1164. 1,
  1165. &res_lib_confdb_reload,
  1166. sizeof (struct res_lib_confdb_reload));
  1167. if (error != CS_OK) {
  1168. /* FIXME: set error_text */
  1169. goto error_exit;
  1170. }
  1171. error = res_lib_confdb_reload.header.error;
  1172. if(res_lib_confdb_reload.error.length) {
  1173. memcpy(error_text, res_lib_confdb_reload.error.value,
  1174. MIN(res_lib_confdb_reload.error.length,errbuf_len));
  1175. error_text[errbuf_len-1] = '\0';
  1176. }
  1177. error_exit:
  1178. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1179. return (error);
  1180. }
  1181. cs_error_t confdb_track_changes (
  1182. confdb_handle_t handle,
  1183. hdb_handle_t object_handle,
  1184. unsigned int flags)
  1185. {
  1186. cs_error_t error;
  1187. struct confdb_inst *confdb_inst;
  1188. struct iovec iov;
  1189. struct req_lib_confdb_object_track_start req;
  1190. coroipc_response_header_t res;
  1191. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1192. if (error != CS_OK) {
  1193. return (error);
  1194. }
  1195. if (confdb_inst->standalone) {
  1196. error = CS_ERR_NOT_SUPPORTED;
  1197. goto error_exit;
  1198. }
  1199. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1200. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1201. req.object_handle = object_handle;
  1202. req.flags = flags;
  1203. iov.iov_base = (char *)&req;
  1204. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1205. error = coroipcc_msg_send_reply_receive (
  1206. confdb_inst->handle,
  1207. &iov,
  1208. 1,
  1209. &res,
  1210. sizeof (coroipc_response_header_t));
  1211. if (error != CS_OK) {
  1212. goto error_exit;
  1213. }
  1214. error = res.error;
  1215. error_exit:
  1216. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1217. return (error);
  1218. }
  1219. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1220. {
  1221. cs_error_t error;
  1222. struct confdb_inst *confdb_inst;
  1223. struct iovec iov;
  1224. coroipc_request_header_t req;
  1225. coroipc_response_header_t res;
  1226. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1227. if (error != CS_OK) {
  1228. return (error);
  1229. }
  1230. if (confdb_inst->standalone) {
  1231. error = CS_ERR_NOT_SUPPORTED;
  1232. goto error_exit;
  1233. }
  1234. req.size = sizeof (coroipc_request_header_t);
  1235. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1236. iov.iov_base = (char *)&req;
  1237. iov.iov_len = sizeof (coroipc_request_header_t);
  1238. error = coroipcc_msg_send_reply_receive (
  1239. confdb_inst->handle,
  1240. &iov,
  1241. 1,
  1242. &res,
  1243. sizeof (coroipc_response_header_t));
  1244. if (error != CS_OK) {
  1245. goto error_exit;
  1246. }
  1247. error = res.error;
  1248. error_exit:
  1249. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1250. return (error);
  1251. }