summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2009-07-23 15:18:26 -0500
committerDavid Teigland <teigland@redhat.com>2009-07-23 15:19:57 -0500
commitafacc1df7d610afdc28c2b30482e581ff8e9f672 (patch)
tree1a042213b514298dc796315606a5bb8f06bf26d0
parenteb761dc4dbd163345075a8fd7580a3b3544c9d40 (diff)
downloaddct-stuff-afacc1df7d610afdc28c2b30482e581ff8e9f672.tar.gz
dct-stuff-afacc1df7d610afdc28c2b30482e581ff8e9f672.tar.xz
dct-stuff-afacc1df7d610afdc28c2b30482e581ff8e9f672.zip
cpgx: let events wrap around event buffer
Signed-off-by: David Teigland <teigland@redhat.com>
-rw-r--r--cpgx/cpgx.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/cpgx/cpgx.c b/cpgx/cpgx.c
index 5de0c03..bb041bc 100644
--- a/cpgx/cpgx.c
+++ b/cpgx/cpgx.c
@@ -171,9 +171,9 @@ static uint8_t our_nodeid;
static uint32_t eventid;
static uint32_t last_config_eventid;
static uint32_t sync_max = DEFAULT_SYNC_MAX;
-static int history_len;
-static struct event *history;
-static struct dct_config *last_config;
+static int events_len;
+static struct event *events;
+static struct dct_config last_config;
static struct list_head nodes;
static struct list_head saved_events;
@@ -378,6 +378,11 @@ void cluster_dead(int ci)
cluster_down = 1;
}
+static inline struct event *history(uint32_t id)
+{
+ return &events[id % HISTORY_EVENTS];
+}
+
struct node *get_node(uint8_t nodeid)
{
struct node *node;
@@ -464,7 +469,7 @@ void init_join_eventid(struct node *node)
int i = eventid - 1;
while (1) {
- ev = &history[i];
+ ev = history(i);
c = &ev->config;
if ((c->type == EV_CONFCHG) && in_join(c, node->nodeid)) {
@@ -774,7 +779,7 @@ void send_time(void)
hd->event_count = count;
for (i = start_eventid; i < end_eventid + 1; i++) {
- memcpy(ev, &history[i], sizeof(struct event));
+ memcpy(ev, history(i), sizeof(struct event));
ev++;
}
@@ -783,8 +788,6 @@ void send_time(void)
free(buf);
}
-/* TODO: ability to send full history, cpg max message sizes limit us */
-
void send_sync(uint8_t nodeid)
{
char *buf;
@@ -845,7 +848,7 @@ void send_sync(uint8_t nodeid)
memcpy(hd->synced_nodes, node->synced_nodes, 8);
for (i = start_eventid; i < end_eventid + 1; i++) {
- memcpy(ev, &history[i], sizeof(struct event));
+ memcpy(ev, history(i), sizeof(struct event));
ev++;
}
@@ -859,10 +862,10 @@ void send_sync(uint8_t nodeid)
void check_event(struct event *ev_buf)
{
- if (memcmp(ev_buf, &history[ev_buf->eventid], sizeof(struct event))) {
+ if (memcmp(ev_buf, history(ev_buf->eventid), sizeof(struct event))) {
log_error("check_event %u", ev_buf->eventid);
log_event(ev_buf, 1);
- log_event(&history[ev_buf->eventid], 1);
+ log_event(history(ev_buf->eventid), 1);
}
}
@@ -896,7 +899,7 @@ void read_events(struct dct_header *hd, int len, int check_only)
start_eventid = ev_buf->eventid;
for (i = 0; i < count; i++) {
- ev_his = &history[ev_buf->eventid];
+ ev_his = history(ev_buf->eventid);
if (check_only || ev_his->eventid)
check_event(ev_buf);
@@ -918,7 +921,7 @@ void read_events(struct dct_header *hd, int len, int check_only)
first saved event which should be our join config. we remove this
first saved event which overlaps what we got from sync */
- ev_his = &history[end_eventid];
+ ev_his = history(end_eventid);
c1 = &ev_his->config;
if (c1->type != EV_CONFCHG) {
@@ -947,7 +950,7 @@ void read_events(struct dct_header *hd, int len, int check_only)
eventid = end_eventid + 1;
last_config_eventid = end_eventid;
- last_config = c1;
+ memcpy(&last_config, c1, sizeof(struct dct_config));
list_del(&se->list);
free(se);
@@ -955,13 +958,11 @@ void read_events(struct dct_header *hd, int len, int check_only)
init_nodes_list(hd, c1);
}
-/* FIXME: handle eventid going past history size */
-
void add_history_confchg(struct dct_config *c)
{
struct event *ev;
- ev = &history[eventid];
+ ev = history(eventid);
ev->eventid = eventid++;
memcpy(&ev->config, c, sizeof(struct dct_config));
@@ -969,14 +970,14 @@ void add_history_confchg(struct dct_config *c)
_log_config(c, ev->eventid, 0);
last_config_eventid = ev->eventid;
- last_config = &ev->config;
+ memcpy(&last_config, &ev->config, sizeof(struct dct_config));
}
void add_history_message(struct dct_header *h, int len)
{
struct event *ev;
- ev = &history[eventid];
+ ev = history(eventid);
ev->eventid = eventid++;
memcpy(&ev->header, h, sizeof(struct dct_header));
@@ -997,7 +998,7 @@ void read_saved_events(void)
list_for_each_entry_safe(se, safe, &saved_events, list) {
if (se->type == EV_CONFCHG) {
add_history_confchg((struct dct_config *)&se->buf);
- update_nodes_list(last_config, last_config_eventid);
+ update_nodes_list(&last_config, last_config_eventid);
count_c++;
} else {
process_message((struct dct_header *)&se->buf, se->len);
@@ -1204,7 +1205,7 @@ static void confchg_cb(cpg_handle_t handle, const struct cpg_name *group_name,
}
add_history_confchg(&c);
- update_nodes_list(last_config, last_config_eventid);
+ update_nodes_list(&last_config, last_config_eventid);
}
static void receive_sync(struct dct_header *hd, int len)
@@ -1252,10 +1253,10 @@ static void receive_time(struct dct_header *hd, int len)
/* check if the sender is a member of the last configuration */
- if (!in_memb(last_config, hd->nodeid)) {
+ if (!in_memb(&last_config, hd->nodeid)) {
log_error("receive_time from non member");
log_header(hd, 1);
- log_config(last_config, 1);
+ log_config(&last_config, 1);
return;
}
@@ -1296,7 +1297,7 @@ static void receive_time(struct dct_header *hd, int len)
if (hd->last_config != last_config_eventid) {
log_error("receive_time in other config");
log_header(hd, 1);
- log_config(last_config, 1);
+ log_config(&last_config, 1);
}
#endif
}
@@ -1600,7 +1601,7 @@ void loop(void)
srandom(time(NULL));
- memset(history, 0, history_len);
+ memset(events, 0, events_len);
free_nodes_list();
dispatch_count = 0;
@@ -1861,11 +1862,11 @@ int main(int argc, char **argv)
srandom(time(NULL));
- history_len = HISTORY_EVENTS * sizeof(struct event);
+ events_len = HISTORY_EVENTS * sizeof(struct event);
- history = malloc(history_len);
- if (!history) {
- log_error("history no mem %d", history_len);
+ events = malloc(events_len);
+ if (!events) {
+ log_error("events no mem %d", events_len);
exit(-1);
}