| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597 |
- /*
- * 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 <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/coroipc.h>
- #include <corosync/list.h>
- #include "sa-confdb.h"
- /* 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 = cslib_service_connect (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) {
- cslib_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 = cslib_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);
- }
- struct confdb_res_overlay {
- mar_res_header_t header __attribute__((aligned(8)));
- char data[512000];
- };
- 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;
- struct confdb_res_overlay 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 = cslib_dispatch_recv (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) {
- break; /* exit do while cont is 1 loop */
- } else
- if (dispatch_avail == 0) {
- 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.header.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:
- error = CS_ERR_LIBRARY;
- goto error_noput;
- break;
- }
- /*
- * 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,
- int 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 = cslib_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 = cslib_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 = cslib_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 = cslib_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,
- int key_name_len,
- const void *value,
- int 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 = cslib_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,
- int key_name_len,
- const void *value,
- int 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 = cslib_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,
- int key_name_len,
- void *value,
- int *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 = cslib_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,
- int 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 = cslib_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,
- int 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 = cslib_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,
- int key_name_len,
- const void *old_value,
- int old_value_len,
- const void *new_value,
- int 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 = cslib_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,
- int 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 = cslib_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,
- int *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 = cslib_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,
- int *key_name_len,
- void *value,
- int *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 = cslib_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)
- {
- 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) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_write(error_text))
- 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 = cslib_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) {
- 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, res_lib_confdb_write.error.length);
- 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)
- {
- 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) {
- return (error);
- }
- if (confdb_inst->standalone) {
- error = CS_OK;
- if (confdb_sa_reload(flush, error_text))
- 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 = cslib_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) {
- 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, res_lib_confdb_reload.error.length);
- 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 = cslib_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 = cslib_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);
- }
|