confdb.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022
  1. /*
  2. * Copyright (c) 2008-2012 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. struct res_lib_confdb_reload_callback *res_reload_pt;
  234. coroipc_response_header_t *dispatch_data;
  235. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  236. if (error != CS_OK) {
  237. return (error);
  238. }
  239. if (confdb_inst->standalone) {
  240. error = CS_ERR_NOT_SUPPORTED;
  241. goto error_put;
  242. }
  243. /*
  244. * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
  245. * wait indefinitely for CS_DISPATCH_BLOCKING
  246. */
  247. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  248. timeout = 0;
  249. }
  250. do {
  251. error = coroipcc_dispatch_get (
  252. confdb_inst->handle,
  253. (void **)&dispatch_data,
  254. timeout);
  255. if (error == CS_ERR_BAD_HANDLE) {
  256. error = CS_OK;
  257. goto error_put;
  258. }
  259. if (error == CS_ERR_TRY_AGAIN) {
  260. error = CS_OK;
  261. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  262. break; /* exit do while cont is 1 loop */
  263. } else {
  264. continue; /* next poll */
  265. }
  266. }
  267. if (error != CS_OK) {
  268. goto error_put;
  269. }
  270. /*
  271. * Make copy of callbacks, message data, unlock instance, and call callback
  272. * A risk of this dispatch method is that the callback routines may
  273. * operate at the same time that confdbFinalize has been called.
  274. */
  275. memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
  276. /*
  277. * Dispatch incoming message
  278. */
  279. switch (dispatch_data->id) {
  280. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
  281. if (callbacks.confdb_key_change_notify_fn == NULL) {
  282. break;
  283. }
  284. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
  285. callbacks.confdb_key_change_notify_fn(handle,
  286. res_key_changed_pt->change_type,
  287. res_key_changed_pt->object_handle,
  288. res_key_changed_pt->parent_object_handle,
  289. res_key_changed_pt->object_name.value,
  290. res_key_changed_pt->object_name.length,
  291. res_key_changed_pt->key_name.value,
  292. res_key_changed_pt->key_name.length,
  293. res_key_changed_pt->key_value.value,
  294. res_key_changed_pt->key_value.length);
  295. break;
  296. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK2:
  297. if (callbacks.confdb_key_change_notify_fn == NULL) {
  298. break;
  299. }
  300. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
  301. callbacks.confdb_key_change_notify_fn(handle,
  302. res_key_changed_pt->change_type,
  303. res_key_changed_pt->object_handle,
  304. res_key_changed_pt->parent_object_handle,
  305. res_key_changed_pt->object_name.value,
  306. res_key_changed_pt->object_name.length,
  307. res_key_changed_pt->key_name.value,
  308. res_key_changed_pt->key_name.length,
  309. &res_key_changed_pt->key_value.value,
  310. res_key_changed_pt->key_value.length);
  311. break;
  312. case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
  313. if (callbacks.confdb_object_create_change_notify_fn == NULL) {
  314. break;
  315. }
  316. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)dispatch_data;
  317. callbacks.confdb_object_create_change_notify_fn(handle,
  318. res_object_created_pt->object_handle,
  319. res_object_created_pt->parent_object_handle,
  320. res_object_created_pt->name.value,
  321. res_object_created_pt->name.length);
  322. break;
  323. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  324. if (callbacks.confdb_object_delete_change_notify_fn == NULL) {
  325. break;
  326. }
  327. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)dispatch_data;
  328. callbacks.confdb_object_delete_change_notify_fn(handle,
  329. res_object_destroyed_pt->parent_object_handle,
  330. res_object_destroyed_pt->name.value,
  331. res_object_destroyed_pt->name.length);
  332. break;
  333. case MESSAGE_RES_CONFDB_RELOAD_CALLBACK:
  334. if (callbacks.confdb_reload_notify_fn == NULL) {
  335. continue;
  336. }
  337. res_reload_pt = (struct res_lib_confdb_reload_callback *)dispatch_data;
  338. callbacks.confdb_reload_notify_fn(handle,
  339. res_reload_pt->type);
  340. break;
  341. default:
  342. error = coroipcc_dispatch_put (confdb_inst->handle);
  343. if (error == CS_OK) {
  344. error = CS_ERR_LIBRARY;
  345. }
  346. goto error_put;
  347. break;
  348. }
  349. error = coroipcc_dispatch_put (confdb_inst->handle);
  350. if (error == CS_ERR_IN_SHUTDOWN) {
  351. /*
  352. * Mask error.
  353. */
  354. error = CS_OK;
  355. goto error_put;
  356. }
  357. if (error != CS_OK) {
  358. goto error_put;
  359. }
  360. /*
  361. * Determine if more messages should be processed
  362. */
  363. if (dispatch_types == CS_DISPATCH_ONE) {
  364. cont = 0;
  365. }
  366. } while (cont);
  367. error_put:
  368. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  369. return (error);
  370. }
  371. cs_error_t confdb_object_create (
  372. confdb_handle_t handle,
  373. hdb_handle_t parent_object_handle,
  374. const void *object_name,
  375. size_t object_name_len,
  376. hdb_handle_t *object_handle)
  377. {
  378. cs_error_t error;
  379. struct confdb_inst *confdb_inst;
  380. struct iovec iov;
  381. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  382. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  383. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  384. if (error != CS_OK) {
  385. return (error);
  386. }
  387. if (confdb_inst->standalone) {
  388. error = CS_OK;
  389. if (confdb_sa_object_create(parent_object_handle,
  390. object_name, object_name_len,
  391. object_handle))
  392. error = CS_ERR_ACCESS;
  393. goto error_exit;
  394. }
  395. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  396. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  397. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  398. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  399. req_lib_confdb_object_create.object_name.length = object_name_len;
  400. iov.iov_base = (char *)&req_lib_confdb_object_create;
  401. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  402. error = coroipcc_msg_send_reply_receive (
  403. confdb_inst->handle,
  404. &iov,
  405. 1,
  406. &res_lib_confdb_object_create,
  407. sizeof (struct res_lib_confdb_object_create));
  408. if (error != CS_OK) {
  409. goto error_exit;
  410. }
  411. error = res_lib_confdb_object_create.header.error;
  412. *object_handle = res_lib_confdb_object_create.object_handle;
  413. error_exit:
  414. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  415. return (error);
  416. }
  417. cs_error_t confdb_object_destroy (
  418. confdb_handle_t handle,
  419. hdb_handle_t object_handle)
  420. {
  421. cs_error_t error;
  422. struct confdb_inst *confdb_inst;
  423. struct iovec iov;
  424. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  425. coroipc_response_header_t res;
  426. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  427. if (error != CS_OK) {
  428. return (error);
  429. }
  430. if (confdb_inst->standalone) {
  431. error = CS_OK;
  432. if (confdb_sa_object_destroy(object_handle))
  433. error = CS_ERR_ACCESS;
  434. goto error_exit;
  435. }
  436. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  437. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  438. req_lib_confdb_object_destroy.object_handle = object_handle;
  439. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  440. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  441. error = coroipcc_msg_send_reply_receive (
  442. confdb_inst->handle,
  443. &iov,
  444. 1,
  445. &res,
  446. sizeof (coroipc_response_header_t));
  447. if (error != CS_OK) {
  448. goto error_exit;
  449. }
  450. error = res.error;
  451. error_exit:
  452. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  453. return (error);
  454. }
  455. cs_error_t confdb_object_parent_get (
  456. confdb_handle_t handle,
  457. hdb_handle_t object_handle,
  458. hdb_handle_t *parent_object_handle)
  459. {
  460. cs_error_t error;
  461. struct confdb_inst *confdb_inst;
  462. struct iovec iov;
  463. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  464. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  465. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  466. if (error != CS_OK) {
  467. return (error);
  468. }
  469. if (confdb_inst->standalone) {
  470. error = CS_OK;
  471. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  472. error = CS_ERR_ACCESS;
  473. goto error_exit;
  474. }
  475. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  476. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  477. req_lib_confdb_object_parent_get.object_handle = object_handle;
  478. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  479. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  480. error = coroipcc_msg_send_reply_receive (
  481. confdb_inst->handle,
  482. &iov,
  483. 1,
  484. &res_lib_confdb_object_parent_get,
  485. sizeof (struct res_lib_confdb_object_parent_get));
  486. if (error != CS_OK) {
  487. goto error_exit;
  488. }
  489. error = res_lib_confdb_object_parent_get.header.error;
  490. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  491. error_exit:
  492. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  493. return (error);
  494. }
  495. cs_error_t confdb_object_name_get (
  496. confdb_handle_t handle,
  497. hdb_handle_t object_handle,
  498. char *object_name,
  499. size_t *object_name_len)
  500. {
  501. cs_error_t error;
  502. struct confdb_inst *confdb_inst;
  503. struct iovec iov;
  504. struct req_lib_confdb_object_name_get request;
  505. struct res_lib_confdb_object_name_get response;
  506. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  507. if (error != CS_OK) {
  508. return (error);
  509. }
  510. if (confdb_inst->standalone) {
  511. error = CS_OK;
  512. if (confdb_sa_object_name_get(object_handle, object_name, object_name_len))
  513. error = CS_ERR_ACCESS;
  514. goto error_exit;
  515. }
  516. request.header.size = sizeof (struct req_lib_confdb_object_name_get);
  517. request.header.id = MESSAGE_REQ_CONFDB_OBJECT_NAME_GET;
  518. request.object_handle = object_handle;
  519. iov.iov_base = (char *)&request;
  520. iov.iov_len = sizeof (struct req_lib_confdb_object_name_get);
  521. error = coroipcc_msg_send_reply_receive (
  522. confdb_inst->handle,
  523. &iov,
  524. 1,
  525. &response,
  526. sizeof (struct res_lib_confdb_object_name_get));
  527. if (error != CS_OK) {
  528. goto error_exit;
  529. }
  530. error = response.header.error;
  531. if (error == CS_OK) {
  532. *object_name_len = response.object_name.length;
  533. memcpy(object_name, response.object_name.value, *object_name_len);
  534. }
  535. error_exit:
  536. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  537. return (error);
  538. }
  539. static cs_error_t do_find_destroy(
  540. struct confdb_inst *confdb_inst,
  541. hdb_handle_t find_handle)
  542. {
  543. cs_error_t error;
  544. struct iovec iov;
  545. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  546. coroipc_response_header_t res;
  547. if (!find_handle)
  548. return CS_OK;
  549. if (confdb_inst->standalone) {
  550. error = CS_OK;
  551. if (confdb_sa_find_destroy(find_handle))
  552. error = CS_ERR_ACCESS;
  553. goto error_exit;
  554. }
  555. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  556. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  557. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  558. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  559. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  560. error = coroipcc_msg_send_reply_receive (
  561. confdb_inst->handle,
  562. &iov,
  563. 1,
  564. &res,
  565. sizeof (coroipc_response_header_t));
  566. if (error != CS_OK) {
  567. goto error_exit;
  568. }
  569. error = res.error;
  570. error_exit:
  571. return (error);
  572. }
  573. cs_error_t confdb_object_find_destroy(
  574. confdb_handle_t handle,
  575. hdb_handle_t parent_object_handle)
  576. {
  577. struct iter_context *context;
  578. cs_error_t error;
  579. struct confdb_inst *confdb_inst;
  580. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  581. if (error != CS_OK) {
  582. return (error);
  583. }
  584. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  585. if (context == NULL) {
  586. error = CS_ERR_LIBRARY;
  587. goto error_exit;
  588. }
  589. error = do_find_destroy(confdb_inst, context->find_handle);
  590. if (error == CS_OK) {
  591. list_del(&context->list);
  592. free(context);
  593. }
  594. error_exit:
  595. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  596. return error;
  597. }
  598. cs_error_t confdb_object_iter_destroy(
  599. confdb_handle_t handle,
  600. hdb_handle_t parent_object_handle)
  601. {
  602. struct iter_context *context;
  603. cs_error_t error;
  604. struct confdb_inst *confdb_inst;
  605. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  606. if (error != CS_OK) {
  607. return (error);
  608. }
  609. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  610. if (context == NULL) {
  611. error = CS_ERR_LIBRARY;
  612. goto error_exit;
  613. }
  614. error = do_find_destroy(confdb_inst, context->find_handle);
  615. if (error == CS_OK) {
  616. list_del(&context->list);
  617. free(context);
  618. }
  619. error_exit:
  620. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  621. return error;
  622. }
  623. cs_error_t confdb_key_create (
  624. confdb_handle_t handle,
  625. hdb_handle_t parent_object_handle,
  626. const void *key_name,
  627. size_t key_name_len,
  628. const void *value,
  629. size_t value_len)
  630. {
  631. cs_error_t error;
  632. struct confdb_inst *confdb_inst;
  633. struct iovec iov;
  634. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  635. coroipc_response_header_t res;
  636. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  637. if (error != CS_OK) {
  638. return (error);
  639. }
  640. if (confdb_inst->standalone) {
  641. error = CS_OK;
  642. if (confdb_sa_key_create(parent_object_handle,
  643. key_name, key_name_len,
  644. value, value_len))
  645. error = CS_ERR_ACCESS;
  646. goto error_exit;
  647. }
  648. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  649. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  650. req_lib_confdb_key_create.object_handle = parent_object_handle;
  651. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  652. req_lib_confdb_key_create.key_name.length = key_name_len;
  653. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  654. req_lib_confdb_key_create.value.length = value_len;
  655. iov.iov_base = (char *)&req_lib_confdb_key_create;
  656. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  657. error = coroipcc_msg_send_reply_receive (
  658. confdb_inst->handle,
  659. &iov,
  660. 1,
  661. &res,
  662. sizeof (res));
  663. if (error != CS_OK) {
  664. goto error_exit;
  665. }
  666. error = res.error;
  667. error_exit:
  668. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  669. return (error);
  670. }
  671. cs_error_t confdb_key_create_typed (
  672. confdb_handle_t handle,
  673. hdb_handle_t parent_object_handle,
  674. const char *key_name,
  675. const void *value,
  676. size_t value_len,
  677. confdb_value_types_t type)
  678. {
  679. cs_error_t error;
  680. struct confdb_inst *confdb_inst;
  681. struct iovec iov;
  682. struct req_lib_confdb_key_create_typed2 *request;
  683. coroipc_response_header_t res;
  684. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  685. if (error != CS_OK) {
  686. return (error);
  687. }
  688. if (confdb_inst->standalone) {
  689. error = CS_OK;
  690. if (confdb_sa_key_create_typed(parent_object_handle,
  691. key_name, value, value_len, type))
  692. error = CS_ERR_ACCESS;
  693. goto error_exit;
  694. }
  695. request = malloc(sizeof(struct req_lib_confdb_key_create_typed2)+value_len);
  696. if (!request) {
  697. error = CS_ERR_NO_MEMORY;
  698. goto error_exit;
  699. }
  700. request->header.size = sizeof (struct req_lib_confdb_key_create_typed2) + value_len;
  701. request->header.id = MESSAGE_REQ_CONFDB_KEY_CREATE_TYPED2;
  702. request->object_handle = parent_object_handle;
  703. request->key_name.length = strlen(key_name)+1;
  704. memcpy(request->key_name.value, key_name, request->key_name.length);
  705. memcpy(&request->value, value, value_len);
  706. request->value_length = value_len;
  707. request->type = type;
  708. iov.iov_base = (char *)request;
  709. iov.iov_len = request->header.size;
  710. error = coroipcc_msg_send_reply_receive (
  711. confdb_inst->handle,
  712. &iov,
  713. 1,
  714. &res,
  715. sizeof (res));
  716. if (error != CS_OK) {
  717. goto free_exit;
  718. }
  719. error = res.error;
  720. free_exit:
  721. free(request);
  722. error_exit:
  723. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  724. return (error);
  725. }
  726. cs_error_t confdb_key_delete (
  727. confdb_handle_t handle,
  728. hdb_handle_t parent_object_handle,
  729. const void *key_name,
  730. size_t key_name_len,
  731. const void *value,
  732. size_t value_len)
  733. {
  734. cs_error_t error;
  735. struct confdb_inst *confdb_inst;
  736. struct iovec iov;
  737. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  738. coroipc_response_header_t res;
  739. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  740. if (error != CS_OK) {
  741. return (error);
  742. }
  743. if (confdb_inst->standalone) {
  744. error = CS_OK;
  745. if (confdb_sa_key_delete(parent_object_handle,
  746. key_name, key_name_len,
  747. value, value_len))
  748. error = CS_ERR_ACCESS;
  749. goto error_exit;
  750. }
  751. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  752. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  753. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  754. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  755. req_lib_confdb_key_delete.key_name.length = key_name_len;
  756. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  757. req_lib_confdb_key_delete.value.length = value_len;
  758. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  759. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  760. error = coroipcc_msg_send_reply_receive (
  761. confdb_inst->handle,
  762. &iov,
  763. 1,
  764. &res,
  765. sizeof (res));
  766. if (error != CS_OK) {
  767. goto error_exit;
  768. }
  769. error = res.error;
  770. error_exit:
  771. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  772. return (error);
  773. }
  774. cs_error_t confdb_key_get (
  775. confdb_handle_t handle,
  776. hdb_handle_t parent_object_handle,
  777. const void *key_name,
  778. size_t key_name_len,
  779. void *value,
  780. size_t *value_len)
  781. {
  782. cs_error_t error;
  783. struct confdb_inst *confdb_inst;
  784. struct iovec iov;
  785. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  786. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  787. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  788. if (error != CS_OK) {
  789. return (error);
  790. }
  791. if (confdb_inst->standalone) {
  792. error = CS_OK;
  793. if (confdb_sa_key_get(parent_object_handle,
  794. key_name, key_name_len,
  795. value, value_len))
  796. error = CS_ERR_ACCESS;
  797. goto error_exit;
  798. }
  799. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  800. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  801. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  802. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  803. req_lib_confdb_key_get.key_name.length = key_name_len;
  804. iov.iov_base = (char *)&req_lib_confdb_key_get;
  805. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  806. error = coroipcc_msg_send_reply_receive (
  807. confdb_inst->handle,
  808. &iov,
  809. 1,
  810. &res_lib_confdb_key_get,
  811. sizeof (struct res_lib_confdb_key_get));
  812. if (error != CS_OK) {
  813. goto error_exit;
  814. }
  815. error = res_lib_confdb_key_get.header.error;
  816. if (error == CS_OK) {
  817. *value_len = res_lib_confdb_key_get.value.length;
  818. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  819. }
  820. error_exit:
  821. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  822. return (error);
  823. }
  824. cs_error_t confdb_key_get_typed (
  825. confdb_handle_t handle,
  826. hdb_handle_t parent_object_handle,
  827. const char *key_name,
  828. void *value,
  829. size_t *value_len,
  830. confdb_value_types_t *type)
  831. {
  832. cs_error_t error;
  833. struct confdb_inst *confdb_inst;
  834. struct iovec iov;
  835. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  836. struct res_lib_confdb_key_get_typed response;
  837. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  838. if (error != CS_OK) {
  839. return (error);
  840. }
  841. if (confdb_inst->standalone) {
  842. error = CS_OK;
  843. if (confdb_sa_key_get_typed(parent_object_handle,
  844. key_name, &value, value_len, (int*)type))
  845. error = CS_ERR_ACCESS;
  846. goto error_exit;
  847. }
  848. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  849. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED;
  850. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  851. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  852. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  853. iov.iov_base = (char *)&req_lib_confdb_key_get;
  854. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  855. error = coroipcc_msg_send_reply_receive (
  856. confdb_inst->handle,
  857. &iov,
  858. 1,
  859. &response,
  860. sizeof (struct res_lib_confdb_key_get_typed));
  861. if (error != CS_OK) {
  862. goto error_exit;
  863. }
  864. error = response.header.error;
  865. if (error == CS_OK) {
  866. *value_len = response.value.length;
  867. *type = response.type;
  868. memcpy(value, response.value.value, *value_len);
  869. }
  870. error_exit:
  871. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  872. return (error);
  873. }
  874. cs_error_t confdb_key_get_typed2 (
  875. confdb_handle_t handle,
  876. hdb_handle_t parent_object_handle,
  877. const char *key_name,
  878. void **value,
  879. size_t *value_len,
  880. confdb_value_types_t *type)
  881. {
  882. cs_error_t error;
  883. struct confdb_inst *confdb_inst;
  884. struct iovec iov;
  885. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  886. struct res_lib_confdb_key_get_typed2 *response;
  887. void *return_address;
  888. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  889. if (error != CS_OK) {
  890. return (error);
  891. }
  892. if (confdb_inst->standalone) {
  893. error = CS_OK;
  894. if (confdb_sa_key_get_typed(parent_object_handle,
  895. key_name, value, value_len, (int*)type))
  896. error = CS_ERR_ACCESS;
  897. goto error_exit;
  898. }
  899. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  900. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED2;
  901. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  902. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  903. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  904. iov.iov_base = (char *)&req_lib_confdb_key_get;
  905. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  906. error = coroipcc_msg_send_reply_receive_in_buf_get (
  907. confdb_inst->handle,
  908. &iov,
  909. 1,
  910. &return_address);
  911. response = return_address;
  912. if (error != CS_OK) {
  913. goto error_exit;
  914. }
  915. error = response->header.error;
  916. if (error == CS_OK) {
  917. if (!*value) {
  918. /* Allow space for naughty callers to put a NUL for printing */
  919. *value = malloc(response->value_length+1);
  920. if (!*value) {
  921. error = CS_ERR_NO_MEMORY;
  922. goto error_exit;
  923. }
  924. }
  925. memcpy(*value, &response->value, response->value_length);
  926. *value_len = response->value_length;
  927. *type = response->type;
  928. }
  929. coroipcc_msg_send_reply_receive_in_buf_put(confdb_inst->handle);
  930. error_exit:
  931. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  932. return (error);
  933. }
  934. cs_error_t confdb_key_increment (
  935. confdb_handle_t handle,
  936. hdb_handle_t parent_object_handle,
  937. const void *key_name,
  938. size_t key_name_len,
  939. unsigned int *value)
  940. {
  941. cs_error_t error;
  942. struct confdb_inst *confdb_inst;
  943. struct iovec iov;
  944. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  945. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  946. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  947. if (error != CS_OK) {
  948. return (error);
  949. }
  950. if (confdb_inst->standalone) {
  951. error = CS_OK;
  952. if (confdb_sa_key_increment(parent_object_handle,
  953. key_name, key_name_len,
  954. value))
  955. error = CS_ERR_ACCESS;
  956. goto error_exit;
  957. }
  958. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  959. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  960. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  961. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  962. req_lib_confdb_key_get.key_name.length = key_name_len;
  963. iov.iov_base = (char *)&req_lib_confdb_key_get;
  964. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  965. error = coroipcc_msg_send_reply_receive (
  966. confdb_inst->handle,
  967. &iov,
  968. 1,
  969. &res_lib_confdb_key_incdec,
  970. sizeof (struct res_lib_confdb_key_incdec));
  971. if (error != CS_OK) {
  972. goto error_exit;
  973. }
  974. error = res_lib_confdb_key_incdec.header.error;
  975. if (error == CS_OK) {
  976. *value = res_lib_confdb_key_incdec.value;
  977. }
  978. error_exit:
  979. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  980. return (error);
  981. }
  982. cs_error_t confdb_key_decrement (
  983. confdb_handle_t handle,
  984. hdb_handle_t parent_object_handle,
  985. const void *key_name,
  986. size_t key_name_len,
  987. unsigned int *value)
  988. {
  989. cs_error_t error;
  990. struct confdb_inst *confdb_inst;
  991. struct iovec iov;
  992. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  993. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  994. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  995. if (error != CS_OK) {
  996. return (error);
  997. }
  998. if (confdb_inst->standalone) {
  999. error = CS_OK;
  1000. if (confdb_sa_key_decrement(parent_object_handle,
  1001. key_name, key_name_len,
  1002. value))
  1003. error = CS_ERR_ACCESS;
  1004. goto error_exit;
  1005. }
  1006. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  1007. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  1008. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  1009. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  1010. req_lib_confdb_key_get.key_name.length = key_name_len;
  1011. iov.iov_base = (char *)&req_lib_confdb_key_get;
  1012. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  1013. error = coroipcc_msg_send_reply_receive (
  1014. confdb_inst->handle,
  1015. &iov,
  1016. 1,
  1017. &res_lib_confdb_key_incdec,
  1018. sizeof (struct res_lib_confdb_key_incdec));
  1019. if (error != CS_OK) {
  1020. goto error_exit;
  1021. }
  1022. error = res_lib_confdb_key_incdec.header.error;
  1023. if (error == CS_OK) {
  1024. *value = res_lib_confdb_key_incdec.value;
  1025. }
  1026. error_exit:
  1027. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1028. return (error);
  1029. }
  1030. cs_error_t confdb_key_replace (
  1031. confdb_handle_t handle,
  1032. hdb_handle_t parent_object_handle,
  1033. const void *key_name,
  1034. size_t key_name_len,
  1035. const void *old_value,
  1036. size_t old_value_len,
  1037. const void *new_value,
  1038. size_t new_value_len)
  1039. {
  1040. cs_error_t error;
  1041. struct confdb_inst *confdb_inst;
  1042. struct iovec iov;
  1043. struct req_lib_confdb_key_replace2 *req_lib_confdb_key_replace;
  1044. coroipc_response_header_t res;
  1045. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1046. if (error != CS_OK) {
  1047. return (error);
  1048. }
  1049. if (confdb_inst->standalone) {
  1050. error = CS_OK;
  1051. if (confdb_sa_key_replace(parent_object_handle,
  1052. key_name, key_name_len,
  1053. old_value, old_value_len,
  1054. new_value, new_value_len))
  1055. error = CS_ERR_ACCESS;
  1056. goto error_exit;
  1057. }
  1058. req_lib_confdb_key_replace = malloc(sizeof(struct req_lib_confdb_key_replace2) + new_value_len);
  1059. req_lib_confdb_key_replace->header.size = sizeof(struct req_lib_confdb_key_replace2) + new_value_len;
  1060. req_lib_confdb_key_replace->header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE2;
  1061. req_lib_confdb_key_replace->object_handle = parent_object_handle;
  1062. memcpy(req_lib_confdb_key_replace->key_name.value, key_name, key_name_len);
  1063. req_lib_confdb_key_replace->key_name.length = key_name_len;
  1064. memcpy(&req_lib_confdb_key_replace->new_value, new_value, new_value_len);
  1065. req_lib_confdb_key_replace->new_value_length = new_value_len;
  1066. /* Oddly objdb doesn't use the old value, so we don't bother sending it */
  1067. iov.iov_base = (char *)req_lib_confdb_key_replace;
  1068. iov.iov_len = sizeof(struct req_lib_confdb_key_replace2) + new_value_len;
  1069. error = coroipcc_msg_send_reply_receive (
  1070. confdb_inst->handle,
  1071. &iov,
  1072. 1,
  1073. &res,
  1074. sizeof (res));
  1075. if (error != CS_OK) {
  1076. goto free_exit;
  1077. }
  1078. error = res.error;
  1079. free_exit:
  1080. free(req_lib_confdb_key_replace);
  1081. error_exit:
  1082. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1083. return (error);
  1084. }
  1085. cs_error_t confdb_object_iter_start (
  1086. confdb_handle_t handle,
  1087. hdb_handle_t object_handle)
  1088. {
  1089. struct confdb_inst *confdb_inst;
  1090. cs_error_t error = CS_OK;
  1091. struct iter_context *context;
  1092. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1093. if (error != CS_OK) {
  1094. return (error);
  1095. }
  1096. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  1097. if (!context) {
  1098. context = malloc(sizeof(struct iter_context));
  1099. if (!context) {
  1100. error = CS_ERR_NO_MEMORY;
  1101. goto ret;
  1102. }
  1103. context->parent_object_handle = object_handle;
  1104. context->find_handle = 0;
  1105. list_add(&context->list, &confdb_inst->object_iter_head);
  1106. }
  1107. /* Start a new find context */
  1108. if (context->find_handle) {
  1109. (void)do_find_destroy(confdb_inst, context->find_handle);
  1110. context->find_handle = 0;
  1111. }
  1112. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1113. ret:
  1114. return error;
  1115. }
  1116. cs_error_t confdb_key_iter_start (
  1117. confdb_handle_t handle,
  1118. hdb_handle_t object_handle)
  1119. {
  1120. struct confdb_inst *confdb_inst;
  1121. cs_error_t error = CS_OK;
  1122. struct iter_context *context;
  1123. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1124. if (error != CS_OK) {
  1125. return (error);
  1126. }
  1127. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  1128. if (!context) {
  1129. context = malloc(sizeof(struct iter_context));
  1130. if (!context) {
  1131. error = CS_ERR_NO_MEMORY;
  1132. goto ret;
  1133. }
  1134. context->parent_object_handle = object_handle;
  1135. list_add(&context->list, &confdb_inst->key_iter_head);
  1136. }
  1137. context->find_handle = 0;
  1138. context->next_entry = 0;
  1139. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1140. ret:
  1141. return error;
  1142. }
  1143. cs_error_t confdb_object_find_start (
  1144. confdb_handle_t handle,
  1145. hdb_handle_t parent_object_handle)
  1146. {
  1147. struct confdb_inst *confdb_inst;
  1148. cs_error_t error = CS_OK;
  1149. struct iter_context *context;
  1150. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1151. if (error != CS_OK) {
  1152. return (error);
  1153. }
  1154. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1155. if (!context) {
  1156. context = malloc(sizeof(struct iter_context));
  1157. if (!context) {
  1158. error = CS_ERR_NO_MEMORY;
  1159. goto ret;
  1160. }
  1161. context->find_handle = 0;
  1162. context->parent_object_handle = parent_object_handle;
  1163. list_add(&context->list, &confdb_inst->object_find_head);
  1164. }
  1165. /* Start a new find context */
  1166. if (context->find_handle) {
  1167. (void)do_find_destroy(confdb_inst, context->find_handle);
  1168. context->find_handle = 0;
  1169. }
  1170. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1171. ret:
  1172. return error;
  1173. }
  1174. cs_error_t confdb_object_find (
  1175. confdb_handle_t handle,
  1176. hdb_handle_t parent_object_handle,
  1177. const void *object_name,
  1178. size_t object_name_len,
  1179. hdb_handle_t *object_handle)
  1180. {
  1181. cs_error_t error;
  1182. struct confdb_inst *confdb_inst;
  1183. struct iovec iov;
  1184. struct iter_context *context;
  1185. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  1186. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  1187. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1188. if (error != CS_OK) {
  1189. return (error);
  1190. }
  1191. /* You MUST call confdb_object_find_start first */
  1192. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1193. if (!context) {
  1194. error = CS_ERR_CONTEXT_NOT_FOUND;
  1195. goto error_exit;
  1196. }
  1197. if (confdb_inst->standalone) {
  1198. error = CS_OK;
  1199. if (confdb_sa_object_find(parent_object_handle,
  1200. &context->find_handle,
  1201. object_handle,
  1202. object_name, object_name_len))
  1203. error = CS_ERR_ACCESS;
  1204. goto error_exit;
  1205. }
  1206. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  1207. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  1208. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  1209. req_lib_confdb_object_find.find_handle = context->find_handle;
  1210. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  1211. req_lib_confdb_object_find.object_name.length = object_name_len;
  1212. iov.iov_base = (char *)&req_lib_confdb_object_find;
  1213. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  1214. error = coroipcc_msg_send_reply_receive (
  1215. confdb_inst->handle,
  1216. &iov,
  1217. 1,
  1218. &res_lib_confdb_object_find,
  1219. sizeof (struct res_lib_confdb_object_find));
  1220. if (error != CS_OK) {
  1221. goto error_exit;
  1222. }
  1223. error = res_lib_confdb_object_find.header.error;
  1224. *object_handle = res_lib_confdb_object_find.object_handle;
  1225. context->find_handle = res_lib_confdb_object_find.find_handle;
  1226. error_exit:
  1227. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1228. return (error);
  1229. }
  1230. cs_error_t confdb_object_iter (
  1231. confdb_handle_t handle,
  1232. hdb_handle_t parent_object_handle,
  1233. hdb_handle_t *object_handle,
  1234. void *object_name,
  1235. size_t *object_name_len)
  1236. {
  1237. cs_error_t error;
  1238. struct confdb_inst *confdb_inst;
  1239. struct iovec iov;
  1240. struct iter_context *context;
  1241. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1242. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1243. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1244. if (error != CS_OK) {
  1245. return (error);
  1246. }
  1247. /* You MUST call confdb_object_iter_start first */
  1248. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1249. if (!context) {
  1250. error = CS_ERR_CONTEXT_NOT_FOUND;
  1251. goto error_exit;
  1252. }
  1253. if (confdb_inst->standalone) {
  1254. error = CS_OK;
  1255. *object_name_len = 0;
  1256. if (confdb_sa_object_iter(parent_object_handle,
  1257. &context->find_handle,
  1258. object_handle,
  1259. NULL, 0,
  1260. object_name, object_name_len))
  1261. error = CS_ERR_ACCESS;
  1262. goto sa_exit;
  1263. }
  1264. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1265. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1266. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1267. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1268. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1269. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1270. error = coroipcc_msg_send_reply_receive (
  1271. confdb_inst->handle,
  1272. &iov,
  1273. 1,
  1274. &res_lib_confdb_object_iter,
  1275. sizeof (struct res_lib_confdb_object_iter));
  1276. if (error != CS_OK) {
  1277. goto error_exit;
  1278. }
  1279. error = res_lib_confdb_object_iter.header.error;
  1280. if (error == CS_OK) {
  1281. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1282. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1283. *object_handle = res_lib_confdb_object_iter.object_handle;
  1284. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1285. }
  1286. sa_exit:
  1287. error_exit:
  1288. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1289. return (error);
  1290. }
  1291. cs_error_t confdb_key_iter (
  1292. confdb_handle_t handle,
  1293. hdb_handle_t parent_object_handle,
  1294. void *key_name,
  1295. size_t *key_name_len,
  1296. void *value,
  1297. size_t *value_len)
  1298. {
  1299. cs_error_t error;
  1300. struct confdb_inst *confdb_inst;
  1301. struct iovec iov;
  1302. struct iter_context *context;
  1303. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1304. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1305. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1306. if (error != CS_OK) {
  1307. return (error);
  1308. }
  1309. /* You MUST call confdb_key_iter_start first */
  1310. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1311. if (!context) {
  1312. error = CS_ERR_CONTEXT_NOT_FOUND;
  1313. goto error_exit;
  1314. }
  1315. if (confdb_inst->standalone) {
  1316. error = CS_OK;
  1317. if (confdb_sa_key_iter(parent_object_handle,
  1318. context->next_entry,
  1319. key_name, key_name_len,
  1320. value, value_len))
  1321. error = CS_ERR_ACCESS;
  1322. goto sa_exit;
  1323. }
  1324. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1325. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1326. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1327. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1328. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1329. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1330. error = coroipcc_msg_send_reply_receive (
  1331. confdb_inst->handle,
  1332. &iov,
  1333. 1,
  1334. &res_lib_confdb_key_iter,
  1335. sizeof (struct res_lib_confdb_key_iter));
  1336. if (error != CS_OK) {
  1337. goto error_exit;
  1338. }
  1339. error = res_lib_confdb_key_iter.header.error;
  1340. if (error == CS_OK) {
  1341. char* key_name_str = (char*)key_name;
  1342. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1343. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1344. key_name_str[res_lib_confdb_key_iter.key_name.length] = '\0';
  1345. *value_len = res_lib_confdb_key_iter.value.length;
  1346. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1347. }
  1348. sa_exit:
  1349. context->next_entry++;
  1350. error_exit:
  1351. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1352. return (error);
  1353. }
  1354. cs_error_t confdb_key_iter_typed (
  1355. confdb_handle_t handle,
  1356. hdb_handle_t parent_object_handle,
  1357. char *key_name,
  1358. void *value,
  1359. size_t *value_len,
  1360. confdb_value_types_t *type)
  1361. {
  1362. cs_error_t error;
  1363. struct confdb_inst *confdb_inst;
  1364. struct iovec iov;
  1365. struct iter_context *context;
  1366. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1367. struct res_lib_confdb_key_iter_typed response;
  1368. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1369. if (error != CS_OK) {
  1370. return (error);
  1371. }
  1372. /* You MUST call confdb_key_iter_start first */
  1373. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1374. if (!context) {
  1375. error = CS_ERR_CONTEXT_NOT_FOUND;
  1376. goto error_exit;
  1377. }
  1378. if (confdb_inst->standalone) {
  1379. error = CS_OK;
  1380. if (confdb_sa_key_iter_typed(parent_object_handle,
  1381. context->next_entry,
  1382. key_name,
  1383. &value, value_len, (int*)type))
  1384. error = CS_ERR_ACCESS;
  1385. goto sa_exit;
  1386. }
  1387. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1388. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED;
  1389. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1390. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1391. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1392. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1393. error = coroipcc_msg_send_reply_receive (
  1394. confdb_inst->handle,
  1395. &iov,
  1396. 1,
  1397. &response,
  1398. sizeof (struct res_lib_confdb_key_iter_typed));
  1399. if (error != CS_OK) {
  1400. goto error_exit;
  1401. }
  1402. error = response.header.error;
  1403. if (error == CS_OK) {
  1404. memcpy(key_name, response.key_name.value, response.key_name.length);
  1405. key_name[response.key_name.length] = '\0';
  1406. *value_len = response.value.length;
  1407. memcpy(value, response.value.value, *value_len);
  1408. *type = response.type;
  1409. }
  1410. sa_exit:
  1411. context->next_entry++;
  1412. error_exit:
  1413. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1414. return (error);
  1415. }
  1416. cs_error_t confdb_key_iter_typed2 (
  1417. confdb_handle_t handle,
  1418. hdb_handle_t parent_object_handle,
  1419. char *key_name,
  1420. void **value,
  1421. size_t *value_len,
  1422. confdb_value_types_t *type)
  1423. {
  1424. cs_error_t error;
  1425. struct confdb_inst *confdb_inst;
  1426. struct iovec iov;
  1427. struct iter_context *context;
  1428. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1429. struct res_lib_confdb_key_iter_typed2 *response;
  1430. void *return_address;
  1431. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1432. if (error != CS_OK) {
  1433. return (error);
  1434. }
  1435. /* You MUST call confdb_key_iter_start first */
  1436. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1437. if (!context) {
  1438. error = CS_ERR_CONTEXT_NOT_FOUND;
  1439. goto error_exit;
  1440. }
  1441. if (confdb_inst->standalone) {
  1442. error = CS_OK;
  1443. if (confdb_sa_key_iter_typed(parent_object_handle,
  1444. context->next_entry,
  1445. key_name,
  1446. value, value_len, (int*)type))
  1447. error = CS_ERR_ACCESS;
  1448. goto sa_exit;
  1449. }
  1450. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1451. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED2;
  1452. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1453. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1454. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1455. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1456. error = coroipcc_msg_send_reply_receive_in_buf_get (
  1457. confdb_inst->handle,
  1458. &iov,
  1459. 1,
  1460. &return_address);
  1461. response = return_address;
  1462. if (error != CS_OK) {
  1463. goto error_exit;
  1464. }
  1465. error = response->header.error;
  1466. if (error == CS_OK) {
  1467. if (!*value) {
  1468. /* Allow space for naughty callers to put a NUL for printing */
  1469. *value = malloc(response->value_length+1);
  1470. if (!*value) {
  1471. error = CS_ERR_NO_MEMORY;
  1472. goto error_exit;
  1473. }
  1474. }
  1475. memcpy(key_name, response->key_name.value, response->key_name.length);
  1476. key_name[response->key_name.length] = '\0';
  1477. memcpy(*value, &response->value, response->value_length);
  1478. *value_len = response->value_length;
  1479. *type = response->type;
  1480. }
  1481. coroipcc_msg_send_reply_receive_in_buf_put(confdb_inst->handle);
  1482. sa_exit:
  1483. context->next_entry++;
  1484. error_exit:
  1485. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1486. return (error);
  1487. }
  1488. cs_error_t confdb_write (
  1489. confdb_handle_t handle,
  1490. char *error_text,
  1491. size_t errbuf_len)
  1492. {
  1493. cs_error_t error;
  1494. struct confdb_inst *confdb_inst;
  1495. struct iovec iov;
  1496. coroipc_request_header_t req;
  1497. struct res_lib_confdb_write res_lib_confdb_write;
  1498. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1499. if (error != CS_OK) {
  1500. /* FIXME: set error_text */
  1501. return (error);
  1502. }
  1503. if (confdb_inst->standalone) {
  1504. error = CS_OK;
  1505. if (confdb_sa_write(error_text, errbuf_len))
  1506. error = CS_ERR_ACCESS;
  1507. goto error_exit;
  1508. }
  1509. req.size = sizeof (coroipc_request_header_t);
  1510. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1511. iov.iov_base = (char *)&req;
  1512. iov.iov_len = sizeof (coroipc_request_header_t);
  1513. error = coroipcc_msg_send_reply_receive (
  1514. confdb_inst->handle,
  1515. &iov,
  1516. 1,
  1517. &res_lib_confdb_write,
  1518. sizeof (struct res_lib_confdb_write));
  1519. if (error != CS_OK) {
  1520. /* FIXME: set error_text */
  1521. goto error_exit;
  1522. }
  1523. error = res_lib_confdb_write.header.error;
  1524. if (res_lib_confdb_write.error.length) {
  1525. memcpy(error_text, res_lib_confdb_write.error.value,
  1526. MIN(res_lib_confdb_write.error.length,errbuf_len));
  1527. error_text[errbuf_len-1] = '\0';
  1528. }
  1529. error_exit:
  1530. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1531. return (error);
  1532. }
  1533. cs_error_t confdb_reload (
  1534. confdb_handle_t handle,
  1535. int flush,
  1536. char *error_text,
  1537. size_t errbuf_len)
  1538. {
  1539. cs_error_t error;
  1540. struct confdb_inst *confdb_inst;
  1541. struct iovec iov;
  1542. struct res_lib_confdb_reload res_lib_confdb_reload;
  1543. struct req_lib_confdb_reload req_lib_confdb_reload;
  1544. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1545. if (error != CS_OK) {
  1546. /* FIXME: set error_text */
  1547. return (error);
  1548. }
  1549. if (confdb_inst->standalone) {
  1550. error = CS_OK;
  1551. if (confdb_sa_reload(flush, error_text, errbuf_len))
  1552. error = CS_ERR_ACCESS;
  1553. goto error_exit;
  1554. }
  1555. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1556. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1557. req_lib_confdb_reload.flush = flush;
  1558. iov.iov_base = (char *)&req_lib_confdb_reload;
  1559. iov.iov_len = sizeof (req_lib_confdb_reload);
  1560. error = coroipcc_msg_send_reply_receive (
  1561. confdb_inst->handle,
  1562. &iov,
  1563. 1,
  1564. &res_lib_confdb_reload,
  1565. sizeof (struct res_lib_confdb_reload));
  1566. if (error != CS_OK) {
  1567. /* FIXME: set error_text */
  1568. goto error_exit;
  1569. }
  1570. error = res_lib_confdb_reload.header.error;
  1571. if(res_lib_confdb_reload.error.length) {
  1572. memcpy(error_text, res_lib_confdb_reload.error.value,
  1573. MIN(res_lib_confdb_reload.error.length,errbuf_len));
  1574. error_text[errbuf_len-1] = '\0';
  1575. }
  1576. error_exit:
  1577. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1578. return (error);
  1579. }
  1580. cs_error_t confdb_track_changes (
  1581. confdb_handle_t handle,
  1582. hdb_handle_t object_handle,
  1583. unsigned int flags)
  1584. {
  1585. cs_error_t error;
  1586. struct confdb_inst *confdb_inst;
  1587. struct iovec iov;
  1588. struct req_lib_confdb_object_track_start req;
  1589. coroipc_response_header_t res;
  1590. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1591. if (error != CS_OK) {
  1592. return (error);
  1593. }
  1594. if (confdb_inst->standalone) {
  1595. error = CS_ERR_NOT_SUPPORTED;
  1596. goto error_exit;
  1597. }
  1598. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1599. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1600. req.object_handle = object_handle;
  1601. req.flags = flags;
  1602. iov.iov_base = (char *)&req;
  1603. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1604. error = coroipcc_msg_send_reply_receive (
  1605. confdb_inst->handle,
  1606. &iov,
  1607. 1,
  1608. &res,
  1609. sizeof (coroipc_response_header_t));
  1610. if (error != CS_OK) {
  1611. goto error_exit;
  1612. }
  1613. error = res.error;
  1614. error_exit:
  1615. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1616. return (error);
  1617. }
  1618. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1619. {
  1620. cs_error_t error;
  1621. struct confdb_inst *confdb_inst;
  1622. struct iovec iov;
  1623. coroipc_request_header_t req;
  1624. coroipc_response_header_t res;
  1625. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1626. if (error != CS_OK) {
  1627. return (error);
  1628. }
  1629. if (confdb_inst->standalone) {
  1630. error = CS_ERR_NOT_SUPPORTED;
  1631. goto error_exit;
  1632. }
  1633. req.size = sizeof (coroipc_request_header_t);
  1634. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1635. iov.iov_base = (char *)&req;
  1636. iov.iov_len = sizeof (coroipc_request_header_t);
  1637. error = coroipcc_msg_send_reply_receive (
  1638. confdb_inst->handle,
  1639. &iov,
  1640. 1,
  1641. &res,
  1642. sizeof (coroipc_response_header_t));
  1643. if (error != CS_OK) {
  1644. goto error_exit;
  1645. }
  1646. error = res.error;
  1647. error_exit:
  1648. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1649. return (error);
  1650. }