confdb.c 39 KB

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