| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613 |
- /*
- * Copyright (c) 2008-2009 Red Hat, Inc.
- *
- * All rights reserved.
- *
- * Author: Christine Caulfield (ccaulfie@redhat.com)
- *
- * This software licensed under BSD license, the text of which follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * - Neither the name of the MontaVista Software, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
- /*
- * Provides access to data in the corosync object database
- */
- #include <config.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <pthread.h>
- #include <sys/types.h>
- #include <errno.h>
- #include <corosync/corotypes.h>
- #include <corosync/confdb.h>
- #include <corosync/ipc_confdb.h>
- #include <corosync/mar_gen.h>
- #include <corosync/coroipcc.h>
- #include <corosync/list.h>
- #include "sa-confdb.h"
- #undef MIN
- #define MIN(x,y) ((x) < (y) ? (x) : (y))
- /* Hold the information for iterators so that
- callers can do recursive tree traversals.
- each object_handle can have its own iterator */
- struct iter_context {
- struct list_head list;
- hdb_handle_t parent_object_handle;
- hdb_handle_t find_handle;
- hdb_handle_t next_entry;
- };
- struct confdb_inst {
- void *ipc_ctx;
- int finalize;
- int standalone;
- confdb_callbacks_t callbacks;
- const void *context;
- pthread_mutex_t response_mutex;
- pthread_mutex_t dispatch_mutex;
- struct list_head object_find_head;
- struct list_head object_iter_head;
- struct list_head key_iter_head;
- };
- static void confdb_instance_destructor (void *instance);
- static struct saHandleDatabase confdb_handle_t_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = confdb_instance_destructor
- };
- static cs_error_t do_find_destroy(struct confdb_inst *confdb_inst, hdb_handle_t find_handle);
- /* Safely tidy one iterator context list */
- static void free_context_list(struct confdb_inst *confdb_inst, struct list_head *list)
- {
- struct iter_context *context;
- struct list_head *iter, *tmp;
- for (iter = list->next, tmp = iter->next;
- iter != list; iter = tmp, tmp = iter->next) {
- context = list_entry (iter, struct iter_context, list);
- (void)do_find_destroy(confdb_inst, context->find_handle);
- free(context);
- }
- }
- /*
- * Clean up function for a confdb instance (confdb_initialize) handle
- */
- static void confdb_instance_destructor (void *instance)
- {
- struct confdb_inst *confdb_inst = instance;
- pthread_mutex_destroy (&confdb_inst->response_mutex);
- pthread_mutex_destroy (&confdb_inst->dispatch_mutex);
- }
- static struct iter_context *find_iter_context(struct list_head *list, hdb_handle_t object_handle)
- {
- struct iter_context *context;
- struct list_head *iter;
- for (iter = list->next;
- iter != list; iter = iter->next) {
- context = list_entry (iter, struct iter_context, list);
- if (context->parent_object_handle == object_handle)
- return context;
- }
- return NULL;
- }
- /**
- * @defgroup confdb_corosync
- * @ingroup corosync
- *
- * @{
- */
- cs_error_t confdb_initialize (
- confdb_handle_t *handle,
- confdb_callbacks_t *callbacks)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- error = saHandleCreate (&confdb_handle_t_db, sizeof (struct confdb_inst), handle);
- if (error != CS_OK) {
- goto error_no_destroy;
- }
- error = saHandleInstanceGet (&confdb_handle_t_db, *handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- goto error_destroy;
- }
- if (getenv("COROSYNC_DEFAULT_CONFIG_IFACE")) {
- error = confdb_sa_init();
- confdb_inst->standalone = 1;
- }
- else {
- error = coroipcc_service_connect (IPC_SOCKET_NAME, CONFDB_SERVICE, &confdb_inst->ipc_ctx);
- }
- if (error != CS_OK)
- goto error_put_destroy;
- memcpy (&confdb_inst->callbacks, callbacks, sizeof (confdb_callbacks_t));
- pthread_mutex_init (&confdb_inst->response_mutex, NULL);
- pthread_mutex_init (&confdb_inst->dispatch_mutex, NULL);
- list_init (&confdb_inst->object_find_head);
- list_init (&confdb_inst->object_iter_head);
- list_init (&confdb_inst->key_iter_head);
- (void)saHandleInstancePut (&confdb_handle_t_db, *handle);
- return (CS_OK);
- error_put_destroy:
- (void)saHandleInstancePut (&confdb_handle_t_db, *handle);
- error_destroy:
- (void)saHandleDestroy (&confdb_handle_t_db, *handle);
- error_no_destroy:
- return (error);
- }
- cs_error_t confdb_finalize (
- confdb_handle_t handle)
- {
- struct confdb_inst *confdb_inst;
- cs_error_t error;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- pthread_mutex_lock (&confdb_inst->response_mutex);
- /*
- * Another thread has already started finalizing
- */
- if (confdb_inst->finalize) {
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (CS_ERR_BAD_HANDLE);
- }
- confdb_inst->finalize = 1;
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- /* Free saved context handles */
- free_context_list(confdb_inst, &confdb_inst->object_find_head);
- free_context_list(confdb_inst, &confdb_inst->object_iter_head);
- free_context_list(confdb_inst, &confdb_inst->key_iter_head);
- if (!confdb_inst->standalone) {
- coroipcc_service_disconnect (confdb_inst->ipc_ctx);
- }
- (void)saHandleDestroy (&confdb_handle_t_db, handle);
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (CS_OK);
- }
- cs_error_t confdb_fd_get (
- confdb_handle_t handle,
- int *fd)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- *fd = coroipcc_fd_get (confdb_inst->ipc_ctx);
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (CS_OK);
- }
- cs_error_t confdb_context_get (
- confdb_handle_t handle,
- const void **context)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- *context = confdb_inst->context;
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (CS_OK);
- }
- cs_error_t confdb_context_set (
- confdb_handle_t handle,
- const void *context)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- confdb_inst->context = context;
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (CS_OK);
- }
- cs_error_t confdb_dispatch (
- confdb_handle_t handle,
- cs_dispatch_flags_t dispatch_types)
- {
- int timeout = -1;
- cs_error_t error;
- int cont = 1; /* always continue do loop except when set to 0 */
- int dispatch_avail;
- struct confdb_inst *confdb_inst;
- confdb_callbacks_t callbacks;
- struct res_lib_confdb_key_change_callback *res_key_changed_pt;
- struct res_lib_confdb_object_create_callback *res_object_created_pt;
- struct res_lib_confdb_object_destroy_callback *res_object_destroyed_pt;
- mar_res_header_t *dispatch_data;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_ERR_NOT_SUPPORTED;
- goto error_put;
- }
- /*
- * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
- * wait indefinately for SA_DISPATCH_BLOCKING
- */
- if (dispatch_types == CONFDB_DISPATCH_ALL) {
- timeout = 0;
- }
- do {
- pthread_mutex_lock (&confdb_inst->dispatch_mutex);
- dispatch_avail = coroipcc_dispatch_get (
- confdb_inst->ipc_ctx,
- (void **)&dispatch_data,
- timeout);
- /*
- * Handle has been finalized in another thread
- */
- if (confdb_inst->finalize == 1) {
- error = CS_OK;
- pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
- goto error_put;
- }
- if (dispatch_avail == 0 && dispatch_types == CONFDB_DISPATCH_ALL) {
- pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
- break; /* exit do while cont is 1 loop */
- } else
- if (dispatch_avail == 0) {
- pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
- continue; /* next poll */
- }
- /*
- * Make copy of callbacks, message data, unlock instance, and call callback
- * A risk of this dispatch method is that the callback routines may
- * operate at the same time that confdbFinalize has been called.
- */
- memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
- pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
- /*
- * Dispatch incoming message
- */
- switch (dispatch_data->id) {
- case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
- res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
- callbacks.confdb_key_change_notify_fn(handle,
- res_key_changed_pt->change_type,
- res_key_changed_pt->object_handle,
- res_key_changed_pt->parent_object_handle,
- res_key_changed_pt->object_name.value,
- res_key_changed_pt->object_name.length,
- res_key_changed_pt->key_name.value,
- res_key_changed_pt->key_name.length,
- res_key_changed_pt->key_value.value,
- res_key_changed_pt->key_value.length);
- break;
- case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
- res_object_created_pt = (struct res_lib_confdb_object_create_callback *)dispatch_data;
- callbacks.confdb_object_create_change_notify_fn(handle,
- res_object_created_pt->object_handle,
- res_object_created_pt->parent_object_handle,
- res_object_created_pt->name.value,
- res_object_created_pt->name.length);
- break;
- case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
- res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)dispatch_data;
- callbacks.confdb_object_delete_change_notify_fn(handle,
- res_object_destroyed_pt->parent_object_handle,
- res_object_destroyed_pt->name.value,
- res_object_destroyed_pt->name.length);
- break;
- default:
- coroipcc_dispatch_put (confdb_inst->ipc_ctx);
- error = CS_ERR_LIBRARY;
- goto error_noput;
- break;
- }
- coroipcc_dispatch_put (confdb_inst->ipc_ctx);
- /*
- * Determine if more messages should be processed
- * */
- switch (dispatch_types) {
- case CONFDB_DISPATCH_ONE:
- cont = 0;
- break;
- case CONFDB_DISPATCH_ALL:
- break;
- case CONFDB_DISPATCH_BLOCKING:
- break;
- }
- } while (cont);
- error_put:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- error_noput:
- return (error);
- }
- cs_error_t confdb_object_create (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- const void *object_name,
- size_t object_name_len,
- hdb_handle_t *object_handle)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_object_create req_lib_confdb_object_create;
- struct res_lib_confdb_object_create res_lib_confdb_object_create;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_object_create(parent_object_handle,
- object_name, object_name_len,
- object_handle))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
- req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
- req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
- memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
- req_lib_confdb_object_create.object_name.length = object_name_len;
- iov.iov_base = (char *)&req_lib_confdb_object_create;
- iov.iov_len = sizeof (struct req_lib_confdb_object_create);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_object_create,
- sizeof (struct res_lib_confdb_object_create));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res_lib_confdb_object_create.header.error;
- *object_handle = res_lib_confdb_object_create.object_handle;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_object_destroy (
- confdb_handle_t handle,
- hdb_handle_t object_handle)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
- mar_res_header_t res;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_object_destroy(object_handle))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
- req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
- req_lib_confdb_object_destroy.object_handle = object_handle;
- iov.iov_base = (char *)&req_lib_confdb_object_destroy;
- iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res,
- sizeof (mar_res_header_t));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res.error;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_object_parent_get (
- confdb_handle_t handle,
- hdb_handle_t object_handle,
- hdb_handle_t *parent_object_handle)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
- struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
- req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
- req_lib_confdb_object_parent_get.object_handle = object_handle;
- iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
- iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_object_parent_get,
- sizeof (struct res_lib_confdb_object_parent_get));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res_lib_confdb_object_parent_get.header.error;
- *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- static cs_error_t do_find_destroy(
- struct confdb_inst *confdb_inst,
- hdb_handle_t find_handle)
- {
- cs_error_t error;
- struct iovec iov;
- struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
- mar_res_header_t res;
- if (!find_handle)
- return CS_OK;
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_find_destroy(find_handle))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
- req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
- req_lib_confdb_object_find_destroy.find_handle = find_handle;
- iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
- iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res,
- sizeof (mar_res_header_t));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res.error;
- error_exit:
- return (error);
- }
- cs_error_t confdb_object_find_destroy(
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle)
- {
- struct iter_context *context;
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
- error = do_find_destroy(confdb_inst, context->find_handle);
- if (error == CS_OK) {
- list_del(&context->list);
- free(context);
- }
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return error;
- }
- cs_error_t confdb_object_iter_destroy(
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle)
- {
- struct iter_context *context;
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
- error = do_find_destroy(confdb_inst, context->find_handle);
- if (error == CS_OK) {
- list_del(&context->list);
- free(context);
- }
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return error;
- }
- cs_error_t confdb_key_create (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- const void *key_name,
- size_t key_name_len,
- const void *value,
- size_t value_len)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_key_create req_lib_confdb_key_create;
- mar_res_header_t res;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_key_create(parent_object_handle,
- key_name, key_name_len,
- value, value_len))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
- req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
- req_lib_confdb_key_create.object_handle = parent_object_handle;
- memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
- req_lib_confdb_key_create.key_name.length = key_name_len;
- memcpy(req_lib_confdb_key_create.value.value, value, value_len);
- req_lib_confdb_key_create.value.length = value_len;
- iov.iov_base = (char *)&req_lib_confdb_key_create;
- iov.iov_len = sizeof (struct req_lib_confdb_key_create);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res,
- sizeof (res));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res.error;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_key_delete (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- const void *key_name,
- size_t key_name_len,
- const void *value,
- size_t value_len)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
- mar_res_header_t res;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_key_delete(parent_object_handle,
- key_name, key_name_len,
- value, value_len))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
- req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
- req_lib_confdb_key_delete.object_handle = parent_object_handle;
- memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
- req_lib_confdb_key_delete.key_name.length = key_name_len;
- memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
- req_lib_confdb_key_delete.value.length = value_len;
- iov.iov_base = (char *)&req_lib_confdb_key_delete;
- iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res,
- sizeof (res));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res.error;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_key_get (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- const void *key_name,
- size_t key_name_len,
- void *value,
- size_t *value_len)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_key_get req_lib_confdb_key_get;
- struct res_lib_confdb_key_get res_lib_confdb_key_get;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_key_get(parent_object_handle,
- key_name, key_name_len,
- value, value_len))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
- req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
- req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
- memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
- req_lib_confdb_key_get.key_name.length = key_name_len;
- iov.iov_base = (char *)&req_lib_confdb_key_get;
- iov.iov_len = sizeof (struct req_lib_confdb_key_get);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_key_get,
- sizeof (struct res_lib_confdb_key_get));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res_lib_confdb_key_get.header.error;
- if (error == CS_OK) {
- *value_len = res_lib_confdb_key_get.value.length;
- memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
- }
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_key_increment (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- const void *key_name,
- size_t key_name_len,
- unsigned int *value)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_key_get req_lib_confdb_key_get;
- struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_key_increment(parent_object_handle,
- key_name, key_name_len,
- value))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
- req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
- req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
- memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
- req_lib_confdb_key_get.key_name.length = key_name_len;
- iov.iov_base = (char *)&req_lib_confdb_key_get;
- iov.iov_len = sizeof (struct req_lib_confdb_key_get);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_key_incdec,
- sizeof (struct res_lib_confdb_key_incdec));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res_lib_confdb_key_incdec.header.error;
- if (error == CS_OK) {
- *value = res_lib_confdb_key_incdec.value;
- }
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_key_decrement (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- const void *key_name,
- size_t key_name_len,
- unsigned int *value)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_key_get req_lib_confdb_key_get;
- struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_key_decrement(parent_object_handle,
- key_name, key_name_len,
- value))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
- req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
- req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
- memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
- req_lib_confdb_key_get.key_name.length = key_name_len;
- iov.iov_base = (char *)&req_lib_confdb_key_get;
- iov.iov_len = sizeof (struct req_lib_confdb_key_get);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_key_incdec,
- sizeof (struct res_lib_confdb_key_incdec));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res_lib_confdb_key_incdec.header.error;
- if (error == CS_OK) {
- *value = res_lib_confdb_key_incdec.value;
- }
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_key_replace (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- const void *key_name,
- size_t key_name_len,
- const void *old_value,
- size_t old_value_len,
- const void *new_value,
- size_t new_value_len)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
- mar_res_header_t res;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_key_replace(parent_object_handle,
- key_name, key_name_len,
- old_value, old_value_len,
- new_value, new_value_len))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
- req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
- req_lib_confdb_key_replace.object_handle = parent_object_handle;
- memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
- req_lib_confdb_key_replace.key_name.length = key_name_len;
- memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
- req_lib_confdb_key_replace.old_value.length = old_value_len;
- memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
- req_lib_confdb_key_replace.new_value.length = new_value_len;
- iov.iov_base = (char *)&req_lib_confdb_key_replace;
- iov.iov_len = sizeof (struct req_lib_confdb_key_replace);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res,
- sizeof (res));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res.error;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_object_iter_start (
- confdb_handle_t handle,
- hdb_handle_t object_handle)
- {
- struct confdb_inst *confdb_inst;
- cs_error_t error = CS_OK;
- struct iter_context *context;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
- if (!context) {
- context = malloc(sizeof(struct iter_context));
- if (!context) {
- error = CS_ERR_NO_MEMORY;
- goto ret;
- }
- context->parent_object_handle = object_handle;
- context->find_handle = 0;
- list_add(&context->list, &confdb_inst->object_iter_head);
- }
- /* Start a new find context */
- if (context->find_handle) {
- (void)do_find_destroy(confdb_inst, context->find_handle);
- context->find_handle = 0;
- }
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- ret:
- return error;
- }
- cs_error_t confdb_key_iter_start (
- confdb_handle_t handle,
- hdb_handle_t object_handle)
- {
- struct confdb_inst *confdb_inst;
- cs_error_t error = CS_OK;
- struct iter_context *context;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
- if (!context) {
- context = malloc(sizeof(struct iter_context));
- if (!context) {
- error = CS_ERR_NO_MEMORY;
- goto ret;
- }
- context->parent_object_handle = object_handle;
- list_add(&context->list, &confdb_inst->key_iter_head);
- }
- context->find_handle = 0;
- context->next_entry = 0;
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- ret:
- return error;
- }
- cs_error_t confdb_object_find_start (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle)
- {
- struct confdb_inst *confdb_inst;
- cs_error_t error = CS_OK;
- struct iter_context *context;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
- if (!context) {
- context = malloc(sizeof(struct iter_context));
- if (!context) {
- error = CS_ERR_NO_MEMORY;
- goto ret;
- }
- context->find_handle = 0;
- context->parent_object_handle = parent_object_handle;
- list_add(&context->list, &confdb_inst->object_find_head);
- }
- /* Start a new find context */
- if (context->find_handle) {
- (void)do_find_destroy(confdb_inst, context->find_handle);
- context->find_handle = 0;
- }
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- ret:
- return error;
- }
- cs_error_t confdb_object_find (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- const void *object_name,
- size_t object_name_len,
- hdb_handle_t *object_handle)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct iter_context *context;
- struct req_lib_confdb_object_find req_lib_confdb_object_find;
- struct res_lib_confdb_object_find res_lib_confdb_object_find;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- /* You MUST call confdb_object_find_start first */
- context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
- if (!context) {
- error = CS_ERR_CONTEXT_NOT_FOUND;
- goto error_exit;
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_object_find(parent_object_handle,
- &context->find_handle,
- object_handle,
- object_name, object_name_len))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
- req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
- req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
- req_lib_confdb_object_find.find_handle = context->find_handle;
- memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
- req_lib_confdb_object_find.object_name.length = object_name_len;
- iov.iov_base = (char *)&req_lib_confdb_object_find;
- iov.iov_len = sizeof (struct req_lib_confdb_object_find);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_object_find,
- sizeof (struct res_lib_confdb_object_find));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res_lib_confdb_object_find.header.error;
- *object_handle = res_lib_confdb_object_find.object_handle;
- context->find_handle = res_lib_confdb_object_find.find_handle;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_object_iter (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- hdb_handle_t *object_handle,
- void *object_name,
- size_t *object_name_len)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct iter_context *context;
- struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
- struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- /* You MUST call confdb_object_iter_start first */
- context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
- if (!context) {
- error = CS_ERR_CONTEXT_NOT_FOUND;
- goto error_exit;
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- *object_name_len = 0;
- if (confdb_sa_object_iter(parent_object_handle,
- &context->find_handle,
- object_handle,
- NULL, 0,
- object_name, object_name_len))
- error = CS_ERR_ACCESS;
- goto sa_exit;
- }
- req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
- req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
- req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
- req_lib_confdb_object_iter.find_handle = context->find_handle;
- iov.iov_base = (char *)&req_lib_confdb_object_iter;
- iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_object_iter,
- sizeof (struct res_lib_confdb_object_iter));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res_lib_confdb_object_iter.header.error;
- if (error == CS_OK) {
- *object_name_len = res_lib_confdb_object_iter.object_name.length;
- memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
- *object_handle = res_lib_confdb_object_iter.object_handle;
- context->find_handle = res_lib_confdb_object_iter.find_handle;
- }
- sa_exit:
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_key_iter (
- confdb_handle_t handle,
- hdb_handle_t parent_object_handle,
- void *key_name,
- size_t *key_name_len,
- void *value,
- size_t *value_len)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct iter_context *context;
- struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
- struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- /* You MUST call confdb_key_iter_start first */
- context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
- if (!context) {
- error = CS_ERR_CONTEXT_NOT_FOUND;
- goto error_exit;
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_key_iter(parent_object_handle,
- context->next_entry,
- key_name, key_name_len,
- value, value_len))
- error = CS_ERR_ACCESS;
- goto sa_exit;
- }
- req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
- req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
- req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
- req_lib_confdb_key_iter.next_entry= context->next_entry;
- iov.iov_base = (char *)&req_lib_confdb_key_iter;
- iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_key_iter,
- sizeof (struct res_lib_confdb_key_iter));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res_lib_confdb_key_iter.header.error;
- if (error == CS_OK) {
- *key_name_len = res_lib_confdb_key_iter.key_name.length;
- memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
- *value_len = res_lib_confdb_key_iter.value.length;
- memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
- }
- sa_exit:
- context->next_entry++;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_write (
- confdb_handle_t handle,
- char *error_text,
- size_t errbuf_len)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- mar_req_header_t req;
- struct res_lib_confdb_write res_lib_confdb_write;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- /* FIXME: set error_text */
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_write(error_text, errbuf_len))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req.size = sizeof (mar_req_header_t);
- req.id = MESSAGE_REQ_CONFDB_WRITE;
- iov.iov_base = (char *)&req;
- iov.iov_len = sizeof (mar_req_header_t);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_write,
- sizeof (struct res_lib_confdb_write));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- /* FIXME: set error_text */
- goto error_exit;
- }
- error = res_lib_confdb_write.header.error;
- if (res_lib_confdb_write.error.length) {
- memcpy(error_text, res_lib_confdb_write.error.value,
- MIN(res_lib_confdb_write.error.length,errbuf_len));
- error_text[errbuf_len-1] = '\0';
- }
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_reload (
- confdb_handle_t handle,
- int flush,
- char *error_text,
- size_t errbuf_len)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct res_lib_confdb_reload res_lib_confdb_reload;
- struct req_lib_confdb_reload req_lib_confdb_reload;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- /* FIXME: set error_text */
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_reload(flush, error_text, errbuf_len))
- error = CS_ERR_ACCESS;
- goto error_exit;
- }
- req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
- req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
- req_lib_confdb_reload.flush = flush;
- iov.iov_base = (char *)&req_lib_confdb_reload;
- iov.iov_len = sizeof (req_lib_confdb_reload);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res_lib_confdb_reload,
- sizeof (struct res_lib_confdb_reload));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- /* FIXME: set error_text */
- goto error_exit;
- }
- error = res_lib_confdb_reload.header.error;
- if(res_lib_confdb_reload.error.length) {
- memcpy(error_text, res_lib_confdb_reload.error.value,
- MIN(res_lib_confdb_reload.error.length,errbuf_len));
- error_text[errbuf_len-1] = '\0';
- }
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_track_changes (
- confdb_handle_t handle,
- hdb_handle_t object_handle,
- unsigned int flags)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- struct req_lib_confdb_object_track_start req;
- mar_res_header_t res;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_ERR_NOT_SUPPORTED;
- goto error_exit;
- }
- req.header.size = sizeof (struct req_lib_confdb_object_track_start);
- req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
- req.object_handle = object_handle;
- req.flags = flags;
- iov.iov_base = (char *)&req;
- iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res,
- sizeof (mar_res_header_t));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res.error;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
- cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
- {
- cs_error_t error;
- struct confdb_inst *confdb_inst;
- struct iovec iov;
- mar_req_header_t req;
- mar_res_header_t res;
- error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
- if (error != CS_OK) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_ERR_NOT_SUPPORTED;
- goto error_exit;
- }
- req.size = sizeof (mar_req_header_t);
- req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
- iov.iov_base = (char *)&req;
- iov.iov_len = sizeof (mar_req_header_t);
- pthread_mutex_lock (&confdb_inst->response_mutex);
- error = coroipcc_msg_send_reply_receive (
- confdb_inst->ipc_ctx,
- &iov,
- 1,
- &res,
- sizeof (mar_res_header_t));
- pthread_mutex_unlock (&confdb_inst->response_mutex);
- if (error != CS_OK) {
- goto error_exit;
- }
- error = res.error;
- error_exit:
- (void)saHandleInstancePut (&confdb_handle_t_db, handle);
- return (error);
- }
|