confdb.c 37 KB

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