confdb.c 40 KB

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