confdb.c 42 KB

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