Skip to content

Commit

Permalink
Fix: sbd-integration: sync pacemakerd with sbd
Browse files Browse the repository at this point in the history
Add new api as not to make the xml-structure an external interface.
  • Loading branch information
wenningerk committed Dec 17, 2019
1 parent 02de657 commit f9f74c3
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 70 deletions.
76 changes: 38 additions & 38 deletions daemons/pacemakerd/pacemakerd.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,47 +564,47 @@ pcmk_ipc_created(qb_ipcs_connection_t * c)
}

static void
pcmk_handle_ping_request( crm_client_t *c, xmlNode *msg, uint32_t id)
pcmk_handle_ping_request(crm_client_t *c, xmlNode *msg, uint32_t id)
{
const char *value = NULL;
xmlNode *ping = NULL;
xmlNode *reply = NULL;
time_t pinged = time(NULL);
const char *from = crm_element_value(msg, F_CRM_SYS_FROM);

/* Pinged for status */
crm_trace("Pinged from %s.%s",
crm_element_value(msg, F_CRM_ORIGIN),
from?from:"unknown");
ping = create_xml_node(NULL, XML_CRM_TAG_PING);
value = crm_element_value(msg, F_CRM_SYS_TO);
crm_xml_add(ping, XML_PING_ATTR_SYSFROM, value);
crm_xml_add(ping, XML_PING_ATTR_PACEMAKERDSTATE, pacemakerd_state);
crm_xml_add_ll(ping, XML_ATTR_TSTAMP, (long long) pinged);
crm_xml_add(ping, XML_PING_ATTR_STATUS, "ok");
reply = create_reply(msg, ping);
free_xml(ping);
if (reply) {
if (crm_ipcs_send(c, id, reply, crm_ipc_server_event) <= 0) {
crm_err("Failed sending ping-reply");
}
free_xml(reply);
} else {
crm_err("Failed building ping-reply");
const char *value = NULL;
xmlNode *ping = NULL;
xmlNode *reply = NULL;
time_t pinged = time(NULL);
const char *from = crm_element_value(msg, F_CRM_SYS_FROM);

/* Pinged for status */
crm_trace("Pinged from %s.%s",
crm_element_value(msg, F_CRM_ORIGIN),
from?from:"unknown");
ping = create_xml_node(NULL, XML_CRM_TAG_PING);
value = crm_element_value(msg, F_CRM_SYS_TO);
crm_xml_add(ping, XML_PING_ATTR_SYSFROM, value);
crm_xml_add(ping, XML_PING_ATTR_PACEMAKERDSTATE, pacemakerd_state);
crm_xml_add_ll(ping, XML_ATTR_TSTAMP, (long long) pinged);
crm_xml_add(ping, XML_PING_ATTR_STATUS, "ok");
reply = create_reply(msg, ping);
free_xml(ping);
if (reply) {
if (crm_ipcs_send(c, id, reply, crm_ipc_server_event) <= 0) {
crm_err("Failed sending ping-reply");
}
/* just proceed state on sbd pinging us */
if (from && strstr(from, "sbd")) {
if (crm_str_eq(pacemakerd_state,
XML_PING_ATTR_PACEMAKERDSTATE_SHUTDOWNCOMPLETE,
TRUE)) {
shutdown_complete_state_reported_to = c->pid;
} else if (crm_str_eq(pacemakerd_state,
XML_PING_ATTR_PACEMAKERDSTATE_WAITPING,
TRUE)) {
pacemakerd_state = XML_PING_ATTR_PACEMAKERDSTATE_STARTINGDAEMONS;
mainloop_set_trigger(startup_trigger);
}
free_xml(reply);
} else {
crm_err("Failed building ping-reply");
}
/* just proceed state on sbd pinging us */
if (from && strstr(from, "sbd")) {
if (crm_str_eq(pacemakerd_state,
XML_PING_ATTR_PACEMAKERDSTATE_SHUTDOWNCOMPLETE,
TRUE)) {
shutdown_complete_state_reported_to = c->pid;
} else if (crm_str_eq(pacemakerd_state,
XML_PING_ATTR_PACEMAKERDSTATE_WAITPING,
TRUE)) {
pacemakerd_state = XML_PING_ATTR_PACEMAKERDSTATE_STARTINGDAEMONS;
mainloop_set_trigger(startup_trigger);
}
}
}

/* Exit code means? */
Expand Down
2 changes: 1 addition & 1 deletion include/crm/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MAINTAINERCLEANFILES = Makefile.in
headerdir=$(pkgincludedir)/crm/common

header_HEADERS = xml.h ipc.h util.h iso8601.h mainloop.h logging.h results.h \
nvpair.h
nvpair.h pacemakerd_types.h
noinst_HEADERS = cib_secrets.h ipcs.h internal.h alerts_internal.h \
iso8601_internal.h remote_internal.h xml_internal.h \
ipc_internal.h output.h cmdline_internal.h curses_internal.h
70 changes: 70 additions & 0 deletions include/crm/common/pacemakerd_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2004-2019 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/

#ifndef PACEMAKERD_TYPES__H
# define PACEMAKERD_TYPES__H

#ifdef __cplusplus
extern "C" {
#endif

#include <time.h>

enum pacemakerd_conn_state {
pacemakerd_conn_connected,
pacemakerd_conn_disconnected
};

enum pacemakerd_state {
pacemakerd_state_invalid = -1,
pacemakerd_state_init = 0,
pacemakerd_state_starting_daemons,
pacemakerd_state_wait_for_ping,
pacemakerd_state_running,
pacemakerd_state_shutting_down,
pacemakerd_state_shutdown_complete,
pacemakerd_state_max = pacemakerd_state_shutdown_complete,
};

typedef struct pacemakerd_s pacemakerd_t;

typedef struct pacemakerd_api_operations_s {
int (*connect) (pacemakerd_t *pacemakerd, const char *name);
int (*disconnect) (pacemakerd_t *pacemakerd);
void (*free) (pacemakerd_t *pacemakerd);
int (*set_ping_callback) (pacemakerd_t *pacemakerd,
void (*callback) (pacemakerd_t *pacemakerd,
time_t last_good,
enum pacemakerd_state state,
int rc, gpointer userdata),
gpointer userdata);
int (*set_disconnect_callback) (pacemakerd_t *pacemakerd,
void (*callback) (gpointer userdata),
gpointer userdata
);
int (*ping) (pacemakerd_t *pacemakerd, const char *name,
const char *admin_uuid, int call_options);
} pacemakerd_api_operations_t;

struct pacemakerd_s {
enum pacemakerd_conn_state conn_state;
void *pacemakerd_private;
pacemakerd_api_operations_t *cmds;
};

pacemakerd_t * pacemakerd_api_new(void);
void pacemakerd_api_delete(pacemakerd_t * pacemakerd);
enum pacemakerd_state pacemakerd_state_text2enum(const char *state);
const char *pacemakerd_state_enum2text(enum pacemakerd_state state);

#ifdef __cplusplus
}
#endif

#endif // PACEMAKERD_TYPES__H
1 change: 1 addition & 0 deletions lib/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ libcrmcommon_la_SOURCES += utils.c
libcrmcommon_la_SOURCES += watchdog.c
libcrmcommon_la_SOURCES += xml.c
libcrmcommon_la_SOURCES += xpath.c
libcrmcommon_la_SOURCES += pacemakerd_client.c

# It's possible to build the library adding ../gnu/md5.c directly to SOURCES,
# but distclean chokes on that because it tries to include the source's .Plo
Expand Down
Loading

0 comments on commit f9f74c3

Please sign in to comment.