summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2012-07-30 00:14:18 +0000
committerRussell Bryant <russell@russellbryant.com>2012-07-30 00:14:18 +0000
commitfd1114659298072d639b691095825b66252a2f3d (patch)
tree4c9dd5902d681793d7b8c5afaaab73dcafe70d52
parent9850a075b7ebc2f3dc3aff6eebb646ca63e5bb92 (diff)
Add a "corosync ping" CLI command.
This patch adds a new CLI command to the res_corosync module. It is primarily used as a debugging tool. It lets you fire off an event which will cause res_corosync on other nodes in the cluster to place messages into the logger if everything is working ok. It verifies that the corosync communication is working as expected. I didn't put anything in the CHANGES file for this, because this module is new in Asterisk 11. There is already a generic "res_corosync new module" entry in there so I figure that covers it just fine. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370535 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--include/asterisk/event_defs.h4
-rw-r--r--main/event.c8
-rw-r--r--res/res_corosync.c64
3 files changed, 69 insertions, 7 deletions
diff --git a/include/asterisk/event_defs.h b/include/asterisk/event_defs.h
index d1e88360c..d3514f59c 100644
--- a/include/asterisk/event_defs.h
+++ b/include/asterisk/event_defs.h
@@ -58,8 +58,10 @@ enum ast_event_type {
AST_EVENT_PRESENCE_STATE = 0x0a,
/*! Used to alert listeners when a named ACL has changed. */
AST_EVENT_ACL_CHANGE = 0x0b,
+ /*! Send out a ping for debugging distributed events */
+ AST_EVENT_PING = 0x0c,
/*! Number of event types. This should be the last event type + 1 */
- AST_EVENT_TOTAL = 0x0c,
+ AST_EVENT_TOTAL = 0x0d,
};
/*! \brief Event Information Element types */
diff --git a/main/event.c b/main/event.c
index f9cf2f4b3..7470eaddd 100644
--- a/main/event.c
+++ b/main/event.c
@@ -663,6 +663,10 @@ static int dump_cache_cb(void *obj, void *arg, int flags)
/*! \brief Dump the event cache for the subscribed event type */
void ast_event_dump_cache(const struct ast_event_sub *event_sub)
{
+ if (!ast_event_cache[event_sub->type].container) {
+ return;
+ }
+
ao2_callback(ast_event_cache[event_sub->type].container, OBJ_NODATA,
dump_cache_cb, (void *) event_sub);
}
@@ -1211,7 +1215,6 @@ struct ast_event *ast_event_new(enum ast_event_type type, ...)
struct ast_event *event;
enum ast_event_ie_type ie_type;
struct ast_event_ie_val *ie_val;
- int has_ie = 0;
AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
/* Invalid type */
@@ -1262,7 +1265,6 @@ struct ast_event *ast_event_new(enum ast_event_type type, ...)
if (insert) {
AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
- has_ie = 1;
} else {
ast_log(LOG_WARNING, "Unsupported PLTYPE(%d)\n", ie_value->ie_pltype);
}
@@ -1302,7 +1304,7 @@ struct ast_event *ast_event_new(enum ast_event_type type, ...)
}
}
- if (has_ie && !ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
+ if (!ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
/* If the event is originating on this server, add the server's
* entity ID to the event. */
ast_event_append_eid(&event);
diff --git a/res/res_corosync.c b/res/res_corosync.c
index 72c3b6511..e6044c305 100644
--- a/res/res_corosync.c
+++ b/res/res_corosync.c
@@ -50,10 +50,13 @@ static struct {
const char *name;
struct ast_event_sub *sub;
unsigned char publish;
+ unsigned char publish_default;
unsigned char subscribe;
+ unsigned char subscribe_default;
} event_types[] = {
[AST_EVENT_MWI] = { .name = "mwi", },
[AST_EVENT_DEVICE_STATE_CHANGE] = { .name = "device_state", },
+ [AST_EVENT_PING] = { .name = "ping", .publish_default = 1, .subscribe_default = 1 },
};
static struct {
@@ -143,7 +146,18 @@ static void cpg_deliver_cb(cpg_handle_t handle, const struct cpg_name *group_nam
memcpy(event, msg, msg_len);
- ast_event_queue_and_cache(event);
+ if (ast_event_get_type(event) == AST_EVENT_PING) {
+ const struct ast_eid *eid;
+ char buf[128] = "";
+
+ eid = ast_event_get_ie_raw(event, AST_EVENT_IE_EID);
+ ast_eid_to_str(buf, sizeof(buf), (struct ast_eid *) eid);
+ ast_log(LOG_NOTICE, "(cpg_deliver_cb) Got event PING from server with EID: '%s'\n", buf);
+
+ ast_event_queue(event);
+ } else {
+ ast_event_queue_and_cache(event);
+ }
}
static void cpg_confchg_cb(cpg_handle_t handle, const struct cpg_name *group_name,
@@ -280,6 +294,15 @@ static void ast_event_cb(const struct ast_event *event, void *data)
.iov_len = ast_event_get_size(event),
};
+ if (ast_event_get_type(event) == AST_EVENT_PING) {
+ const struct ast_eid *eid;
+ char buf[128] = "";
+
+ eid = ast_event_get_ie_raw(event, AST_EVENT_IE_EID);
+ ast_eid_to_str(buf, sizeof(buf), (struct ast_eid *) eid);
+ ast_log(LOG_NOTICE, "(ast_event_cb) Got event PING from server with EID: '%s'\n", buf);
+ }
+
if (ast_eid_cmp(&ast_eid_default,
ast_event_get_ie_raw(event, AST_EVENT_IE_EID))) {
/* If the event didn't originate from this server, don't send it back out. */
@@ -368,6 +391,40 @@ static char *corosync_show_members(struct ast_cli_entry *e, int cmd, struct ast_
return CLI_SUCCESS;
}
+static char *corosync_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ast_event *event;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "corosync ping";
+ e->usage =
+ "Usage: corosync ping\n"
+ " Send a test ping to the cluster.\n"
+ "A NOTICE will be in the log for every ping received\n"
+ "on a server.\n If you send a ping, you should see a NOTICE\n"
+ "in the log for every server in the cluster.\n";
+ return NULL;
+
+ case CLI_GENERATE:
+ return NULL; /* no completion */
+ }
+
+ if (a->argc != e->args) {
+ return CLI_SHOWUSAGE;
+ }
+
+ event = ast_event_new(AST_EVENT_PING, AST_EVENT_IE_END);
+
+ if (!event) {
+ return CLI_FAILURE;
+ }
+
+ ast_event_queue(event);
+
+ return CLI_SUCCESS;
+}
+
static char *corosync_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
unsigned int i;
@@ -417,6 +474,7 @@ static char *corosync_show_config(struct ast_cli_entry *e, int cmd, struct ast_c
static struct ast_cli_entry corosync_cli[] = {
AST_CLI_DEFINE(corosync_show_config, "Show configuration"),
AST_CLI_DEFINE(corosync_show_members, "Show cluster members"),
+ AST_CLI_DEFINE(corosync_ping, "Send a test ping to the cluster"),
};
enum {
@@ -457,8 +515,8 @@ static int load_general_config(struct ast_config *cfg)
ast_rwlock_wrlock(&event_types_lock);
for (i = 0; i < ARRAY_LEN(event_types); i++) {
- event_types[i].publish = 0;
- event_types[i].subscribe = 0;
+ event_types[i].publish = event_types[i].publish_default;
+ event_types[i].subscribe = event_types[i].subscribe_default;
}
for (v = ast_variable_browse(cfg, "general"); v && !res; v = v->next) {