confdb.c 42 KB

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