19 #include <sys/types.h> 28 static GHashTable *cib_op_callback_table = NULL;
31 int rc, xmlNode * output));
34 void (*callback) (
const char *event, xmlNode * msg));
37 void (*callback) (
const char *event, xmlNode * msg));
41 #define op_common(cib) do { \ 44 } else if(cib->delegate_fn == NULL) { \ 45 return -EPROTONOSUPPORT; \ 50 cib_client_noop(
cib_t * cib,
int call_options)
58 cib_client_ping(
cib_t * cib, xmlNode ** output_data,
int call_options)
65 cib_client_query(
cib_t * cib,
const char *section, xmlNode ** output_data,
int call_options)
67 return cib->
cmds->
query_from(cib, NULL, section, output_data, call_options);
71 cib_client_query_from(
cib_t * cib,
const char *
host,
const char *section,
72 xmlNode ** output_data,
int call_options)
76 output_data, call_options, NULL);
80 is_primary(
cib_t *cib)
88 set_secondary(
cib_t *cib,
int call_options)
92 NULL, call_options, NULL);
96 set_all_secondary(
cib_t * cib,
int call_options)
98 return -EPROTONOSUPPORT;
102 set_primary(
cib_t *cib,
int call_options)
105 crm_trace(
"Adding cib_scope_local to options");
111 cib_client_bump_epoch(
cib_t * cib,
int call_options)
119 cib_client_upgrade(
cib_t * cib,
int call_options)
123 NULL, call_options, NULL);
127 cib_client_sync(
cib_t * cib,
const char *section,
int call_options)
129 return cib->
cmds->
sync_from(cib, NULL, section, call_options);
133 cib_client_sync_from(
cib_t * cib,
const char *
host,
const char *section,
int call_options)
137 NULL, NULL, call_options, NULL);
141 cib_client_create(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
145 NULL, call_options, NULL);
149 cib_client_modify(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
153 NULL, call_options, NULL);
157 cib_client_update(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
161 NULL, call_options, NULL);
165 cib_client_replace(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
169 NULL, call_options, NULL);
173 cib_client_delete(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
177 NULL, call_options, NULL);
181 cib_client_delete_absolute(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
185 data, NULL, call_options, NULL);
189 cib_client_erase(
cib_t * cib, xmlNode ** output_data,
int call_options)
193 output_data, call_options, NULL);
197 cib_destroy_op_callback(gpointer
data)
214 destroy_op_callback_table(
void)
216 if (cib_op_callback_table != NULL) {
217 g_hash_table_destroy(cib_op_callback_table);
218 cib_op_callback_table = NULL;
225 char *cib_home = NULL;
226 char *fullname = NULL;
228 const char *dir = getenv(
"CIB_shadow_dir");
231 uid_t uid = geteuid();
232 struct passwd *pwent = getpwuid(uid);
233 const char *user = NULL;
236 user = pwent->pw_name;
238 user = getenv(
"USER");
240 "Assuming %s because cannot get user details for user ID %d",
241 (user? user :
"unprivileged user"), uid);
248 const char *home = NULL;
250 if ((home = getenv(
"HOME")) == NULL) {
252 home = pwent->pw_dir;
257 if (home && home[0] ==
'/') {
262 rc = mkdir(cib_home, 0700);
263 if (rc < 0 && errno != EEXIST) {
264 crm_perror(LOG_ERR,
"Couldn't create user-specific shadow directory: %s",
285 cib_t *new_cib = NULL;
286 char *shadow_file = NULL;
300 unsetenv(
"CIB_shadow");
307 const char *value = getenv(
"CIB_shadow");
310 if (value && value[0] != 0) {
314 value = getenv(
"CIB_file");
319 value = getenv(
"CIB_port");
321 gboolean encrypted = TRUE;
322 const char *server = getenv(
"CIB_server");
323 const char *user = getenv(
"CIB_user");
324 const char *pass = getenv(
"CIB_passwd");
333 value = getenv(
"CIB_encrypted");
341 crm_info(
"Defaulting to user: %s", user);
344 if (server == NULL) {
345 server =
"localhost";
346 crm_info(
"Defaulting to localhost");
367 cib_t *new_cib = NULL;
369 new_cib = calloc(1,
sizeof(
cib_t));
371 if (new_cib == NULL) {
390 if (new_cib->
cmds == NULL) {
401 new_cib->
cmds->
noop = cib_client_noop;
402 new_cib->
cmds->
ping = cib_client_ping;
404 new_cib->
cmds->
sync = cib_client_sync;
441 while (list != NULL) {
444 list = g_list_remove(list, client);
460 destroy_op_callback_table();
479 int rc, xmlNode * output))
481 if (callback == NULL) {
482 crm_info(
"Un-Setting operation callback");
493 void (*callback) (
const char *event, xmlNode * msg))
495 GList *list_item = NULL;
499 return -EPROTONOSUPPORT;
505 new_client->
event = event;
510 if (list_item != NULL) {
511 crm_warn(
"Callback already present");
526 get_notify_list_event_count(
cib_t * cib,
const char *event)
531 for (l = g_list_first(cib->
notify_list); l; l = g_list_next(l)) {
534 if (strcmp(client->
event, event) == 0) {
538 crm_trace(
"event(%s) count : %d", event, count);
544 void (*callback) (
const char *event, xmlNode * msg))
546 GList *list_item = NULL;
550 return -EPROTONOSUPPORT;
553 if (get_notify_list_event_count(cib, event) == 0) {
554 crm_debug(
"The callback of the event does not exist(%s)", event);
558 crm_debug(
"Removing callback for %s events", event);
561 new_client->
event = event;
566 if (list_item != NULL) {
578 if (get_notify_list_event_count(cib, event) == 0) {
595 rc = strcmp(a_client->
event, b_client->
event);
600 crm_trace(
"callbacks for %s are not equal: %p < %p",
604 crm_trace(
"callbacks for %s are not equal: %p > %p",
612 cib_async_timeout_handler(gpointer
data)
627 void *user_data,
const char *callback_name,
628 void (*callback) (xmlNode *,
int,
int, xmlNode *,
void *))
631 only_success, user_data,
632 callback_name, callback, NULL);
637 gboolean only_success,
void *user_data,
638 const char *callback_name,
639 void (*callback)(xmlNode *,
int,
int,
641 void (*free_func)(
void *))
646 if (only_success == FALSE) {
651 if (user_data && free_func) {
652 free_func(user_data);
658 blob->
id = callback_name;
667 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
668 blob->
timer = async_timer;
674 g_timeout_add(async_timer->
timeout, cib_async_timeout_handler, async_timer);
678 pcmk__intkey_table_insert(cib_op_callback_table,
call_id, blob);
687 destroy_op_callback_table();
688 cib_op_callback_table = pcmk__intkey_table(cib_destroy_op_callback);
690 pcmk__intkey_table_remove(cib_op_callback_table,
call_id);
697 if (cib_op_callback_table == NULL) {
700 return g_hash_table_size(cib_op_callback_table);
704 cib_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
706 int call = GPOINTER_TO_INT(key);
709 crm_debug(
"Call %d (%s): pending", call, pcmk__s(blob->
id,
"without ID"));
715 if (cib_op_callback_table == NULL) {
718 return g_hash_table_foreach(cib_op_callback_table, cib_dump_pending_op, NULL);
724 return pcmk__intkey_table_lookup(cib_op_callback_table,
call_id);
#define CRM_CHECK(expr, failure_action)
const char * pcmk_strerror(int rc)
gboolean(* register_callback)(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *))
cib_t * cib_remote_new(const char *server, const char *user, const char *passwd, int port, gboolean encrypted)
int cib_client_add_notify_callback(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
#define PCMK__CIB_REQUEST_PRIMARY
void cib_dump_pending_callbacks(void)
#define PCMK__CIB_REQUEST_CREATE
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
int(* delete_absolute)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int cib_client_del_notify_callback(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
gboolean(* register_callback_full)(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *), void(*free_func)(void *))
void(* callback)(const char *event, xmlNode *msg)
#define PCMK__CIB_REQUEST_QUERY
void cib_free_callbacks(cib_t *cib)
Free all callbacks for a CIB connection.
cib_t * cib_shadow_new(const char *shadow)
int(* set_secondary)(cib_t *cib, int call_options)
Set the local CIB manager as a secondary instance.
#define PCMK__CIB_REQUEST_ERASE
int(* set_op_callback)(cib_t *cib, void(*callback)(const xmlNode *msg, int callid, int rc, xmlNode *output))
int(* sync)(cib_t *cib, const char *section, int call_options)
#define PCMK__CIB_REQUEST_ABS_DELETE
gboolean cib_client_register_callback_full(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *), void(*free_func)(void *))
#define crm_warn(fmt, args...)
struct timer_rec_s * timer
int(* query_from)(cib_t *cib, const char *host, const char *section, xmlNode **output_data, int call_options)
int pcmk__scan_port(const char *text, int *port)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
int num_cib_op_callbacks(void)
int(* set_slave)(cib_t *cib, int call_options)
#define PCMK__CIB_REQUEST_IS_PRIMARY
gboolean cib_client_register_callback(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *))
void(* callback)(xmlNode *, int, int, xmlNode *, void *)
#define crm_trace(fmt, args...)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
int(* modify)(cib_t *cib, const char *section, xmlNode *data, int call_options)
void(* op_callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output)
char * get_shadow_file(const char *suffix)
int(* create)(cib_t *cib, const char *section, xmlNode *data, int call_options)
Wrappers for and extensions to libxml2.
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
int(* is_master)(cib_t *cib)
cib_t * cib_new_no_shadow(void)
cib_t * cib_native_new(void)
int(* replace)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int(* add_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
int(* sync_from)(cib_t *cib, const char *host, const char *section, int call_options)
int(* register_notification)(cib_t *cib, const char *callback, int enabled)
int(* ping)(cib_t *cib, xmlNode **output_data, int call_options)
int(* update)(cib_t *cib, const char *section, xmlNode *data, int call_options)
#define PCMK__CIB_REQUEST_UPGRADE
cib_t * cib_file_new(const char *filename)
cib_callback_client_t * cib__lookup_id(int call_id)
int cib_client_set_op_callback(cib_t *cib, void(*callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output))
#define PCMK__CIB_REQUEST_BUMP
int(* set_primary)(cib_t *cib, int call_options)
Set the local CIB manager as the cluster's primary instance.
int(* noop)(cib_t *cib, int call_options)
const char * pcmk__get_tmpdir(void)
int(* set_slave_all)(cib_t *cib, int call_options)
int(* del_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
void cib_free_notify(cib_t *cib)
#define PCMK__CIB_REQUEST_REPLACE
int(* set_master)(cib_t *cib, int call_options)
#define PCMK__CIB_REQUEST_SYNC_TO_ALL
#define PCMK__CIB_REQUEST_SECONDARY
#define PCMK__CIB_REQUEST_NOOP
void cib_native_callback(cib_t *cib, xmlNode *msg, int call_id, int rc)
cib_t * cib_new_variant(void)
int(* bump_epoch)(cib_t *cib, int call_options)
gboolean crm_is_true(const char *s)
#define PCMK__CIB_REQUEST_MODIFY
int(* remove)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int cib_internal_op(cib_t *cib, const char *op, const char *host, const char *section, xmlNode *data, xmlNode **output_data, int call_options, const char *user_name)
void cib_delete(cib_t *cib)
Free all memory used by CIB connection.
void(* free_func)(void *)
int(* upgrade)(cib_t *cib, int call_options)
#define crm_info(fmt, args...)
int(* erase)(cib_t *cib, xmlNode **output_data, int call_options)
void remove_cib_op_callback(int call_id, gboolean all_callbacks)
#define PCMK__CIB_REQUEST_DELETE
gint ciblib_GCompareFunc(gconstpointer a, gconstpointer b)