Skip to content

Commit

Permalink
Merge branch '1.1' of github.com:ClusterLabs/pacemaker into 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
beekhof committed May 15, 2015
2 parents be75b5b + 0b79da3 commit 26180cd
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
95 changes: 93 additions & 2 deletions cib/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <notify.h>
#include "common.h"

static unsigned long cib_local_bcast_num = 0;

typedef struct cib_local_notify_s {
xmlNode *notify_src;
char *client_id;
Expand All @@ -48,7 +50,13 @@ typedef struct cib_local_notify_s {
} cib_local_notify_t;

int next_client_id = 0;

#if SUPPORT_PLUGIN
gboolean legacy_mode = TRUE;
#else
gboolean legacy_mode = FALSE;
#endif

qb_ipcs_service_t *ipcs_ro = NULL;
qb_ipcs_service_t *ipcs_rw = NULL;
qb_ipcs_service_t *ipcs_shm = NULL;
Expand Down Expand Up @@ -82,8 +90,12 @@ static gboolean cib_read_legacy_mode(void)
return legacy;
}

static gboolean cib_legacy_mode(void)
gboolean cib_legacy_mode(void)
{
#if SUPPORT_PLUGIN
return TRUE;
#endif

if(cib_read_legacy_mode()) {
return TRUE;
}
Expand Down Expand Up @@ -441,6 +453,54 @@ do_local_notify(xmlNode * notify_src, const char *client_id,
}
}

static void
local_notify_destroy_callback(gpointer data)
{
cib_local_notify_t *notify = data;

free_xml(notify->notify_src);
free(notify->client_id);
free(notify);
}

static void
check_local_notify(int bcast_id)
{
cib_local_notify_t *notify = NULL;

if (!local_notify_queue) {
return;
}

notify = g_hash_table_lookup(local_notify_queue, GINT_TO_POINTER(bcast_id));

if (notify) {
do_local_notify(notify->notify_src, notify->client_id, notify->sync_reply,
notify->from_peer);
g_hash_table_remove(local_notify_queue, GINT_TO_POINTER(bcast_id));
}
}

static void
queue_local_notify(xmlNode * notify_src, const char *client_id, gboolean sync_reply,
gboolean from_peer)
{
cib_local_notify_t *notify = calloc(1, sizeof(cib_local_notify_t));

notify->notify_src = notify_src;
notify->client_id = strdup(client_id);
notify->sync_reply = sync_reply;
notify->from_peer = from_peer;

if (!local_notify_queue) {
local_notify_queue = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
local_notify_destroy_callback);
}

g_hash_table_insert(local_notify_queue, GINT_TO_POINTER(cib_local_bcast_num), notify);
}

static void
parse_local_options_v1(crm_client_t * cib_client, int call_type, int call_options, const char *host,
const char *op, gboolean * local_notify, gboolean * needs_reply,
Expand Down Expand Up @@ -814,9 +874,12 @@ send_peer_reply(xmlNode * msg, xmlNode * result_diff, const char *originator, gb
int diff_del_admin_epoch = 0;

const char *digest = NULL;
int format = 1;

CRM_LOG_ASSERT(result_diff != NULL);
digest = crm_element_value(result_diff, XML_ATTR_DIGEST);
crm_element_value_int(result_diff, "format", &format);

cib_diff_version_details(result_diff,
&diff_add_admin_epoch, &diff_add_epoch, &diff_add_updates,
&diff_del_admin_epoch, &diff_del_epoch, &diff_del_updates);
Expand All @@ -829,7 +892,9 @@ send_peer_reply(xmlNode * msg, xmlNode * result_diff, const char *originator, gb
crm_xml_add(msg, F_CIB_GLOBAL_UPDATE, XML_BOOLEAN_TRUE);
crm_xml_add(msg, F_CIB_OPERATION, CIB_OP_APPLY_DIFF);

CRM_ASSERT(digest != NULL);
if (format == 1) {
CRM_ASSERT(digest != NULL);
}

add_message_xml(msg, F_CIB_UPDATE_DIFF, result_diff);
crm_log_xml_explicit(msg, "copy");
Expand Down Expand Up @@ -1039,6 +1104,27 @@ cib_process_request(xmlNode * request, gboolean force_synchronous, gboolean priv
*/
crm_trace("Completed slave update");

} else if (cib_legacy_mode() &&
rc == pcmk_ok && result_diff != NULL && !(call_options & cib_inhibit_bcast)) {
gboolean broadcast = FALSE;

cib_local_bcast_num++;
crm_xml_add_int(request, F_CIB_LOCAL_NOTIFY_ID, cib_local_bcast_num);
broadcast = send_peer_reply(request, result_diff, originator, TRUE);

if (broadcast && client_id && local_notify && op_reply) {

/* If we have been asked to sync the reply,
* and a bcast msg has gone out, we queue the local notify
* until we know the bcast message has been received */
local_notify = FALSE;
crm_trace("Queuing local %ssync notification for %s",
(call_options & cib_sync_call) ? "" : "a-", client_id);

queue_local_notify(op_reply, client_id, (call_options & cib_sync_call), from_peer);
op_reply = NULL; /* the reply is queued, so don't free here */
}

} else if (call_options & cib_discard_reply) {
crm_trace("Caller isn't interested in reply");

Expand Down Expand Up @@ -1322,6 +1408,11 @@ cib_peer_callback(xmlNode * msg, void *private_data)

if (cib_legacy_mode() && (originator == NULL || crm_str_eq(originator, cib_our_uname, TRUE))) {
/* message is from ourselves */
int bcast_id = 0;

if (!(crm_element_value_int(msg, F_CIB_LOCAL_NOTIFY_ID, &bcast_id))) {
check_local_notify(bcast_id);
}
return;

} else if (crm_peer_cache == NULL) {
Expand Down
2 changes: 2 additions & 0 deletions cib/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ void cib_shutdown(int nsig);
void initiate_exit(void);
void terminate_cib(const char *caller, gboolean fast);

extern gboolean cib_legacy_mode(void);

#if SUPPORT_HEARTBEAT
extern void cib_ha_peer_callback(HA_Message * msg, void *private_data);
extern int cib_ccm_dispatch(gpointer user_data);
Expand Down
9 changes: 8 additions & 1 deletion cib/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,14 @@ cib_process_upgrade_server(const char *op, int options, const char *section, xml
crm_xml_add(up, F_CIB_CALLOPTS, crm_element_value(req, F_CIB_CALLOPTS));
crm_xml_add(up, F_CIB_CALLID, crm_element_value(req, F_CIB_CALLID));

send_cluster_message(NULL, crm_msg_cib, up, FALSE);
if (cib_legacy_mode() && cib_is_master) {
rc = cib_process_upgrade(
op, options, section, up, input, existing_cib, result_cib, answer);

} else {
send_cluster_message(NULL, crm_msg_cib, up, FALSE);
}

free_xml(up);

} else if(rc == pcmk_ok) {
Expand Down
6 changes: 6 additions & 0 deletions lib/common/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -3408,12 +3408,18 @@ dump_xml_attr(xmlAttrPtr attr, int options, char **buffer, int *offset, int *max
{
char *p_value = NULL;
const char *p_name = NULL;
xml_private_t *p = NULL;

CRM_ASSERT(buffer != NULL);
if (attr == NULL || attr->children == NULL) {
return;
}

p = attr->_private;
if (is_set(p->flags, xpf_deleted)) {
return;
}

p_name = (const char *)attr->name;
p_value = crm_xml_escape((const char *)attr->children->content);
buffer_print(*buffer, *max, *offset, " %s=\"%s\"", p_name, p_value);
Expand Down

0 comments on commit 26180cd

Please sign in to comment.