confdb.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  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 confdb_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 confdb_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_increment (
  730. confdb_handle_t handle,
  731. unsigned int parent_object_handle,
  732. void *key_name,
  733. int key_name_len,
  734. unsigned int *value)
  735. {
  736. confdb_error_t error;
  737. struct confdb_inst *confdb_inst;
  738. struct iovec iov[2];
  739. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  740. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  741. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  742. if (error != SA_AIS_OK) {
  743. return (error);
  744. }
  745. if (confdb_inst->standalone) {
  746. error = SA_AIS_OK;
  747. if (confdb_sa_key_increment(parent_object_handle,
  748. key_name, key_name_len,
  749. value))
  750. error = SA_AIS_ERR_ACCESS;
  751. goto error_exit;
  752. }
  753. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  754. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  755. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  756. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  757. req_lib_confdb_key_get.key_name.length = key_name_len;
  758. iov[0].iov_base = (char *)&req_lib_confdb_key_get;
  759. iov[0].iov_len = sizeof (struct req_lib_confdb_key_get);
  760. pthread_mutex_lock (&confdb_inst->response_mutex);
  761. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  762. &res_lib_confdb_key_incdec, sizeof (struct res_lib_confdb_key_incdec));
  763. pthread_mutex_unlock (&confdb_inst->response_mutex);
  764. if (error != SA_AIS_OK) {
  765. goto error_exit;
  766. }
  767. error = res_lib_confdb_key_incdec.header.error;
  768. if (error == SA_AIS_OK) {
  769. *value = res_lib_confdb_key_incdec.value;
  770. }
  771. error_exit:
  772. saHandleInstancePut (&confdb_handle_t_db, handle);
  773. return (error);
  774. }
  775. confdb_error_t confdb_key_decrement (
  776. confdb_handle_t handle,
  777. unsigned int parent_object_handle,
  778. void *key_name,
  779. int key_name_len,
  780. unsigned int *value)
  781. {
  782. confdb_error_t error;
  783. struct confdb_inst *confdb_inst;
  784. struct iovec iov[2];
  785. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  786. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  787. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  788. if (error != SA_AIS_OK) {
  789. return (error);
  790. }
  791. if (confdb_inst->standalone) {
  792. error = SA_AIS_OK;
  793. if (confdb_sa_key_decrement(parent_object_handle,
  794. key_name, key_name_len,
  795. value))
  796. error = SA_AIS_ERR_ACCESS;
  797. goto error_exit;
  798. }
  799. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  800. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  801. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  802. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  803. req_lib_confdb_key_get.key_name.length = key_name_len;
  804. iov[0].iov_base = (char *)&req_lib_confdb_key_get;
  805. iov[0].iov_len = sizeof (struct req_lib_confdb_key_get);
  806. pthread_mutex_lock (&confdb_inst->response_mutex);
  807. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  808. &res_lib_confdb_key_incdec, sizeof (struct res_lib_confdb_key_incdec));
  809. pthread_mutex_unlock (&confdb_inst->response_mutex);
  810. if (error != SA_AIS_OK) {
  811. goto error_exit;
  812. }
  813. error = res_lib_confdb_key_incdec.header.error;
  814. if (error == SA_AIS_OK) {
  815. *value = res_lib_confdb_key_incdec.value;
  816. }
  817. error_exit:
  818. saHandleInstancePut (&confdb_handle_t_db, handle);
  819. return (error);
  820. }
  821. confdb_error_t confdb_key_replace (
  822. confdb_handle_t handle,
  823. unsigned int parent_object_handle,
  824. void *key_name,
  825. int key_name_len,
  826. void *old_value,
  827. int old_value_len,
  828. void *new_value,
  829. int new_value_len)
  830. {
  831. confdb_error_t error;
  832. struct confdb_inst *confdb_inst;
  833. struct iovec iov[2];
  834. struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
  835. mar_res_header_t res;
  836. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  837. if (error != SA_AIS_OK) {
  838. return (error);
  839. }
  840. if (confdb_inst->standalone) {
  841. error = SA_AIS_OK;
  842. if (confdb_sa_key_replace(parent_object_handle,
  843. key_name, key_name_len,
  844. old_value, old_value_len,
  845. new_value, new_value_len))
  846. error = SA_AIS_ERR_ACCESS;
  847. goto error_exit;
  848. }
  849. req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
  850. req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
  851. req_lib_confdb_key_replace.object_handle = parent_object_handle;
  852. memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
  853. req_lib_confdb_key_replace.key_name.length = key_name_len;
  854. memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
  855. req_lib_confdb_key_replace.old_value.length = old_value_len;
  856. memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
  857. req_lib_confdb_key_replace.new_value.length = new_value_len;
  858. iov[0].iov_base = (char *)&req_lib_confdb_key_replace;
  859. iov[0].iov_len = sizeof (struct req_lib_confdb_key_replace);
  860. pthread_mutex_lock (&confdb_inst->response_mutex);
  861. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  862. &res, sizeof (res));
  863. pthread_mutex_unlock (&confdb_inst->response_mutex);
  864. if (error != SA_AIS_OK) {
  865. goto error_exit;
  866. }
  867. error = res.error;
  868. error_exit:
  869. saHandleInstancePut (&confdb_handle_t_db, handle);
  870. return (error);
  871. }
  872. confdb_error_t confdb_object_iter_start (
  873. confdb_handle_t handle,
  874. unsigned int object_handle)
  875. {
  876. struct confdb_inst *confdb_inst;
  877. confdb_error_t error = SA_AIS_OK;
  878. struct iter_context *context;
  879. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  880. if (error != SA_AIS_OK) {
  881. return (error);
  882. }
  883. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  884. if (!context) {
  885. context = malloc(sizeof(struct iter_context));
  886. if (!context) {
  887. error = CONFDB_ERR_NO_MEMORY;
  888. goto ret;
  889. }
  890. context->parent_object_handle = object_handle;
  891. context->find_handle = 0;
  892. list_add(&context->list, &confdb_inst->object_iter_head);
  893. }
  894. /* Start a new find context */
  895. if (context->find_handle) {
  896. do_find_destroy(confdb_inst, context->find_handle);
  897. context->find_handle = 0;
  898. }
  899. saHandleInstancePut (&confdb_handle_t_db, handle);
  900. ret:
  901. return error;
  902. }
  903. confdb_error_t confdb_key_iter_start (
  904. confdb_handle_t handle,
  905. unsigned int object_handle)
  906. {
  907. struct confdb_inst *confdb_inst;
  908. confdb_error_t error = SA_AIS_OK;
  909. struct iter_context *context;
  910. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  911. if (error != SA_AIS_OK) {
  912. return (error);
  913. }
  914. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  915. if (!context) {
  916. context = malloc(sizeof(struct iter_context));
  917. if (!context) {
  918. error = CONFDB_ERR_NO_MEMORY;
  919. goto ret;
  920. }
  921. context->parent_object_handle = object_handle;
  922. list_add(&context->list, &confdb_inst->key_iter_head);
  923. }
  924. context->find_handle = 0;
  925. context->next_entry = 0;
  926. saHandleInstancePut (&confdb_handle_t_db, handle);
  927. ret:
  928. return error;
  929. }
  930. confdb_error_t confdb_object_find_start (
  931. confdb_handle_t handle,
  932. unsigned int parent_object_handle)
  933. {
  934. struct confdb_inst *confdb_inst;
  935. confdb_error_t error = SA_AIS_OK;
  936. struct iter_context *context;
  937. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  938. if (error != SA_AIS_OK) {
  939. return (error);
  940. }
  941. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  942. if (!context) {
  943. context = malloc(sizeof(struct iter_context));
  944. if (!context) {
  945. error = CONFDB_ERR_NO_MEMORY;
  946. goto ret;
  947. }
  948. context->find_handle = 0;
  949. context->parent_object_handle = parent_object_handle;
  950. list_add(&context->list, &confdb_inst->object_find_head);
  951. }
  952. /* Start a new find context */
  953. if (context->find_handle) {
  954. do_find_destroy(confdb_inst, context->find_handle);
  955. context->find_handle = 0;
  956. }
  957. saHandleInstancePut (&confdb_handle_t_db, handle);
  958. ret:
  959. return error;
  960. }
  961. confdb_error_t confdb_object_find (
  962. confdb_handle_t handle,
  963. unsigned int parent_object_handle,
  964. void *object_name,
  965. int object_name_len,
  966. unsigned int *object_handle)
  967. {
  968. confdb_error_t error;
  969. struct confdb_inst *confdb_inst;
  970. struct iovec iov[2];
  971. struct iter_context *context;
  972. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  973. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  974. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  975. if (error != SA_AIS_OK) {
  976. return (error);
  977. }
  978. /* You MUST call confdb_object_find_start first */
  979. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  980. if (!context) {
  981. error = CONFDB_ERR_CONTEXT_NOT_FOUND;
  982. goto error_exit;
  983. }
  984. if (confdb_inst->standalone) {
  985. error = SA_AIS_OK;
  986. if (confdb_sa_object_find(parent_object_handle,
  987. &context->find_handle,
  988. object_handle,
  989. object_name, &object_name_len,
  990. 0))
  991. error = SA_AIS_ERR_ACCESS;
  992. goto error_exit;
  993. }
  994. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  995. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  996. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  997. req_lib_confdb_object_find.find_handle = context->find_handle;
  998. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  999. req_lib_confdb_object_find.object_name.length = object_name_len;
  1000. iov[0].iov_base = (char *)&req_lib_confdb_object_find;
  1001. iov[0].iov_len = sizeof (struct req_lib_confdb_object_find);
  1002. pthread_mutex_lock (&confdb_inst->response_mutex);
  1003. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  1004. &res_lib_confdb_object_find, sizeof (struct res_lib_confdb_object_find));
  1005. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1006. if (error != SA_AIS_OK) {
  1007. goto error_exit;
  1008. }
  1009. error = res_lib_confdb_object_find.header.error;
  1010. *object_handle = res_lib_confdb_object_find.object_handle;
  1011. context->find_handle = res_lib_confdb_object_find.find_handle;
  1012. error_exit:
  1013. saHandleInstancePut (&confdb_handle_t_db, handle);
  1014. return (error);
  1015. }
  1016. confdb_error_t confdb_object_iter (
  1017. confdb_handle_t handle,
  1018. unsigned int parent_object_handle,
  1019. unsigned int *object_handle,
  1020. void *object_name,
  1021. int *object_name_len)
  1022. {
  1023. confdb_error_t error;
  1024. struct confdb_inst *confdb_inst;
  1025. struct iovec iov[2];
  1026. struct iter_context *context;
  1027. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1028. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1029. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1030. if (error != SA_AIS_OK) {
  1031. return (error);
  1032. }
  1033. /* You MUST call confdb_object_iter_start first */
  1034. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1035. if (!context) {
  1036. error = CONFDB_ERR_CONTEXT_NOT_FOUND;
  1037. goto error_exit;
  1038. }
  1039. if (confdb_inst->standalone) {
  1040. error = SA_AIS_OK;
  1041. *object_name_len = 0;
  1042. if (confdb_sa_object_find(parent_object_handle,
  1043. &context->find_handle,
  1044. object_handle,
  1045. object_name, object_name_len,
  1046. 1))
  1047. error = SA_AIS_ERR_ACCESS;
  1048. goto sa_exit;
  1049. }
  1050. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1051. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1052. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1053. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1054. iov[0].iov_base = (char *)&req_lib_confdb_object_iter;
  1055. iov[0].iov_len = sizeof (struct req_lib_confdb_object_iter);
  1056. pthread_mutex_lock (&confdb_inst->response_mutex);
  1057. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  1058. &res_lib_confdb_object_iter, sizeof (struct res_lib_confdb_object_iter));
  1059. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1060. if (error != SA_AIS_OK) {
  1061. goto error_exit;
  1062. }
  1063. error = res_lib_confdb_object_iter.header.error;
  1064. if (error == SA_AIS_OK) {
  1065. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1066. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1067. *object_handle = res_lib_confdb_object_iter.object_handle;
  1068. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1069. }
  1070. sa_exit:
  1071. error_exit:
  1072. saHandleInstancePut (&confdb_handle_t_db, handle);
  1073. return (error);
  1074. }
  1075. confdb_error_t confdb_key_iter (
  1076. confdb_handle_t handle,
  1077. unsigned int parent_object_handle,
  1078. void *key_name,
  1079. int *key_name_len,
  1080. void *value,
  1081. int *value_len)
  1082. {
  1083. confdb_error_t error;
  1084. struct confdb_inst *confdb_inst;
  1085. struct iovec iov[2];
  1086. struct iter_context *context;
  1087. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1088. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1089. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1090. if (error != SA_AIS_OK) {
  1091. return (error);
  1092. }
  1093. /* You MUST call confdb_key_iter_start first */
  1094. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1095. if (!context) {
  1096. error = CONFDB_ERR_CONTEXT_NOT_FOUND;
  1097. goto error_exit;
  1098. }
  1099. if (confdb_inst->standalone) {
  1100. error = SA_AIS_OK;
  1101. if (confdb_sa_key_iter(parent_object_handle,
  1102. context->next_entry,
  1103. key_name, key_name_len,
  1104. value, value_len))
  1105. error = SA_AIS_ERR_ACCESS;
  1106. goto sa_exit;
  1107. }
  1108. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1109. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1110. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1111. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1112. iov[0].iov_base = (char *)&req_lib_confdb_key_iter;
  1113. iov[0].iov_len = sizeof (struct req_lib_confdb_key_iter);
  1114. pthread_mutex_lock (&confdb_inst->response_mutex);
  1115. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  1116. &res_lib_confdb_key_iter, sizeof (struct res_lib_confdb_key_iter));
  1117. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1118. if (error != SA_AIS_OK) {
  1119. goto error_exit;
  1120. }
  1121. error = res_lib_confdb_key_iter.header.error;
  1122. if (error == SA_AIS_OK) {
  1123. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1124. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1125. *value_len = res_lib_confdb_key_iter.value.length;
  1126. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1127. }
  1128. sa_exit:
  1129. context->next_entry++;
  1130. error_exit:
  1131. saHandleInstancePut (&confdb_handle_t_db, handle);
  1132. return (error);
  1133. }
  1134. confdb_error_t confdb_write (
  1135. confdb_handle_t handle,
  1136. char *error_text)
  1137. {
  1138. confdb_error_t error;
  1139. struct confdb_inst *confdb_inst;
  1140. struct iovec iov[2];
  1141. mar_req_header_t req;
  1142. struct res_lib_confdb_write res_lib_confdb_write;
  1143. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1144. if (error != SA_AIS_OK) {
  1145. return (error);
  1146. }
  1147. if (confdb_inst->standalone) {
  1148. error = SA_AIS_OK;
  1149. if (confdb_sa_write(error_text))
  1150. error = SA_AIS_ERR_ACCESS;
  1151. goto error_exit;
  1152. }
  1153. req.size = sizeof (mar_req_header_t);
  1154. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1155. iov[0].iov_base = (char *)&req;
  1156. iov[0].iov_len = sizeof (mar_req_header_t);
  1157. pthread_mutex_lock (&confdb_inst->response_mutex);
  1158. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  1159. &res_lib_confdb_write, sizeof ( struct res_lib_confdb_write));
  1160. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1161. if (error != SA_AIS_OK) {
  1162. goto error_exit;
  1163. }
  1164. error = res_lib_confdb_write.header.error;
  1165. if (res_lib_confdb_write.error.length)
  1166. memcpy(error_text, res_lib_confdb_write.error.value, res_lib_confdb_write.error.length);
  1167. error_exit:
  1168. saHandleInstancePut (&confdb_handle_t_db, handle);
  1169. return (error);
  1170. }
  1171. confdb_error_t confdb_reload (
  1172. confdb_handle_t handle,
  1173. int flush,
  1174. char *error_text)
  1175. {
  1176. confdb_error_t error;
  1177. struct confdb_inst *confdb_inst;
  1178. struct iovec iov[2];
  1179. struct res_lib_confdb_reload res_lib_confdb_reload;
  1180. struct req_lib_confdb_reload req_lib_confdb_reload;
  1181. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1182. if (error != SA_AIS_OK) {
  1183. return (error);
  1184. }
  1185. if (confdb_inst->standalone) {
  1186. error = SA_AIS_OK;
  1187. if (confdb_sa_reload(flush, error_text))
  1188. error = SA_AIS_ERR_ACCESS;
  1189. goto error_exit;
  1190. }
  1191. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1192. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1193. req_lib_confdb_reload.flush = flush;
  1194. iov[0].iov_base = (char *)&req_lib_confdb_reload;
  1195. iov[0].iov_len = sizeof (req_lib_confdb_reload);
  1196. pthread_mutex_lock (&confdb_inst->response_mutex);
  1197. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  1198. &res_lib_confdb_reload, sizeof (struct res_lib_confdb_reload));
  1199. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1200. if (error != SA_AIS_OK) {
  1201. goto error_exit;
  1202. }
  1203. error = res_lib_confdb_reload.header.error;
  1204. if(res_lib_confdb_reload.error.length)
  1205. memcpy(error_text, res_lib_confdb_reload.error.value, res_lib_confdb_reload.error.length);
  1206. error_exit:
  1207. saHandleInstancePut (&confdb_handle_t_db, handle);
  1208. return (error);
  1209. }
  1210. confdb_error_t confdb_track_changes (
  1211. confdb_handle_t handle,
  1212. unsigned int object_handle,
  1213. unsigned int flags)
  1214. {
  1215. confdb_error_t error;
  1216. struct confdb_inst *confdb_inst;
  1217. struct iovec iov[2];
  1218. struct req_lib_confdb_object_track_start req;
  1219. mar_res_header_t res;
  1220. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1221. if (error != SA_AIS_OK) {
  1222. return (error);
  1223. }
  1224. if (confdb_inst->standalone) {
  1225. error = CONFDB_ERR_NOT_SUPPORTED;
  1226. goto error_exit;
  1227. }
  1228. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1229. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1230. req.object_handle = object_handle;
  1231. req.flags = flags;
  1232. iov[0].iov_base = (char *)&req;
  1233. iov[0].iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1234. pthread_mutex_lock (&confdb_inst->response_mutex);
  1235. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  1236. &res, sizeof ( mar_res_header_t));
  1237. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1238. if (error != SA_AIS_OK) {
  1239. goto error_exit;
  1240. }
  1241. error = res.error;
  1242. error_exit:
  1243. saHandleInstancePut (&confdb_handle_t_db, handle);
  1244. return (error);
  1245. }
  1246. confdb_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1247. {
  1248. confdb_error_t error;
  1249. struct confdb_inst *confdb_inst;
  1250. struct iovec iov[2];
  1251. mar_req_header_t req;
  1252. mar_res_header_t res;
  1253. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1254. if (error != SA_AIS_OK) {
  1255. return (error);
  1256. }
  1257. if (confdb_inst->standalone) {
  1258. error = CONFDB_ERR_NOT_SUPPORTED;
  1259. goto error_exit;
  1260. }
  1261. req.size = sizeof (mar_req_header_t);
  1262. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1263. iov[0].iov_base = (char *)&req;
  1264. iov[0].iov_len = sizeof (mar_req_header_t);
  1265. pthread_mutex_lock (&confdb_inst->response_mutex);
  1266. error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
  1267. &res, sizeof ( mar_res_header_t));
  1268. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1269. if (error != SA_AIS_OK) {
  1270. goto error_exit;
  1271. }
  1272. error = res.error;
  1273. error_exit:
  1274. saHandleInstancePut (&confdb_handle_t_db, handle);
  1275. return (error);
  1276. }