commands.c   commands.c 
skipping to change at line 93 skipping to change at line 93
static struct connection *shutdown_con; static struct connection *shutdown_con;
static uint32_t shutdown_flags; static uint32_t shutdown_flags;
static int shutdown_yes; static int shutdown_yes;
static int shutdown_no; static int shutdown_no;
static int shutdown_expected; static int shutdown_expected;
static int ccsd_timer_active = 0; static int ccsd_timer_active = 0;
static struct cluster_node *find_node_by_nodeid(int nodeid); static struct cluster_node *find_node_by_nodeid(int nodeid);
static struct cluster_node *find_node_by_name(char *name); static struct cluster_node *find_node_by_name(char *name);
static int get_node_count(void); static int get_node_count(void);
static int get_highest_nodeid(void);
static int send_port_open_msg(unsigned char port); static int send_port_open_msg(unsigned char port);
static int send_port_enquire(int nodeid); static int send_port_enquire(int nodeid);
static void process_internal_message(char *data, int nodeid, int byteswap); static void process_internal_message(char *data, int nodeid, int byteswap);
static void recalculate_quorum(int allow_decrease, int by_current_nodes); static void recalculate_quorum(int allow_decrease, int by_current_nodes);
static void send_kill(int nodeid, uint16_t reason); static void send_kill(int nodeid, uint16_t reason);
static const char *killmsg_reason(int reason); static const char *killmsg_reason(int reason);
static void ccsd_timer_fn(void *arg); static void ccsd_timer_fn(void *arg);
static int reload_config(int new_version, int should_broadcast); static int reload_config(int new_version, int should_broadcast);
static void set_port_bit(struct cluster_node *node, uint8_t port) static void set_port_bit(struct cluster_node *node, uint8_t port)
skipping to change at line 274 skipping to change at line 273
log_printf(LOG_ERR, "Unable to allocate memory for n ode %s\n", name); log_printf(LOG_ERR, "Unable to allocate memory for n ode %s\n", name);
return NULL; return NULL;
} }
memset(newnode, 0, sizeof(struct cluster_node)); memset(newnode, 0, sizeof(struct cluster_node));
newalloc = 1; newalloc = 1;
newnode->state = state; newnode->state = state;
if (state == NODESTATE_MEMBER) if (state == NODESTATE_MEMBER)
newnode->incarnation = incarnation; newnode->incarnation = incarnation;
} }
if (!newnode->name) { if (!newnode->name) {
newnode->name = malloc(strlen(name)+1); newnode->name = strdup(name);
if (!newnode->name) { if (!newnode->name) {
if (newalloc) if (newalloc)
free(newnode); free(newnode);
return NULL; return NULL;
} }
strcpy(newnode->name, name);
} }
if (!newnode->node_id) /* Don't clobber existing nodeid */ if (!newnode->node_id) /* Don't clobber existing nodeid */
newnode->node_id = nodeid; newnode->node_id = nodeid;
if (votes >= 0) if (votes >= 0)
newnode->votes = votes; newnode->votes = votes;
if (expected_votes) if (expected_votes)
newnode->expected_votes = expected_votes; newnode->expected_votes = expected_votes;
/* If this node has a name passed in then use that rather than a pre vious generated one */ /* If this node has a name passed in then use that rather than a pre vious generated one */
skipping to change at line 401 skipping to change at line 399
static void copy_to_usernode(struct cluster_node *node, static void copy_to_usernode(struct cluster_node *node,
struct cl_cluster_node *unode) struct cl_cluster_node *unode)
{ {
struct sockaddr_storage ss; struct sockaddr_storage ss;
int addrlen=0; int addrlen=0;
unsigned int numaddrs=1; unsigned int numaddrs=1;
char **status; char **status;
struct totem_ip_address node_ifs[INTERFACE_MAX]; struct totem_ip_address node_ifs[INTERFACE_MAX];
/* totempg_ifaces_get always copies INTERFACE_MAX addresses */ /* totempg_ifaces_get always copies INTERFACE_MAX addresses */
strcpy(unode->name, node->name); strncpy(unode->name, node->name, MAX_CLUSTER_MEMBER_NAME_LEN - 1);
unode->jointime = node->join_time; unode->jointime = node->join_time;
unode->size = sizeof(struct cl_cluster_node); unode->size = sizeof(struct cl_cluster_node);
unode->votes = node->votes; unode->votes = node->votes;
unode->state = node->state; unode->state = node->state;
unode->us = node->us; unode->us = node->us;
unode->node_id = node->node_id; unode->node_id = node->node_id;
unode->leave_reason = node->leave_reason; unode->leave_reason = node->leave_reason;
unode->incarnation = node->incarnation; unode->incarnation = node->incarnation;
/* Just send the first address. If the user wants the full set they /* Just send the first address. If the user wants the full set they
skipping to change at line 425 skipping to change at line 423
totemip_to_sockaddr(&node_ifs[0], 0, &ss, &addrlen); totemip_to_sockaddr(&node_ifs[0], 0, &ss, &addrlen);
memcpy(unode->addr, &ss, addrlen); memcpy(unode->addr, &ss, addrlen);
unode->addrlen = addrlen; unode->addrlen = addrlen;
} }
int cman_set_nodename(char *name) int cman_set_nodename(char *name)
{ {
if (ais_running) if (ais_running)
return -EALREADY; return -EALREADY;
strncpy(nodename, name, MAX_CLUSTER_MEMBER_NAME_LEN); strncpy(nodename, name, MAX_CLUSTER_MEMBER_NAME_LEN - 1);
return 0; return 0;
} }
int cman_set_nodeid(int nodeid) int cman_set_nodeid(int nodeid)
{ {
if (ais_running) if (ais_running)
return -EALREADY; return -EALREADY;
wanted_nodeid = nodeid; wanted_nodeid = nodeid;
return 0; return 0;
skipping to change at line 459 skipping to change at line 457
strncpy(cluster_name, name, MAX_CLUSTER_NAME_LEN); strncpy(cluster_name, name, MAX_CLUSTER_NAME_LEN);
two_node = two_node_flag; two_node = two_node_flag;
corosync = api; corosync = api;
quit_threads = 0; quit_threads = 0;
ais_running = 1; ais_running = 1;
/* Make sure we have a node name */ /* Make sure we have a node name */
if (nodename[0] == '\0') { if (nodename[0] == '\0') {
struct utsname un; struct utsname un;
uname(&un); if (uname(&un)) {
strcpy(nodename, un.nodename); return -EINVAL;
}
strncpy(nodename, un.nodename, sizeof(nodename) - 1);
} }
time(&join_time); time(&join_time);
us = add_new_node(nodename, wanted_nodeid, votes, expected_votes, us = add_new_node(nodename, wanted_nodeid, votes, expected_votes,
NODESTATE_DEAD); NODESTATE_DEAD);
set_port_bit(us, 0); set_port_bit(us, 0);
us->us = 1; us->us = 1;
return 0; return 0;
} }
skipping to change at line 565 skipping to change at line 565
if (us->flags & NODE_FLAGS_DIRTY) if (us->flags & NODE_FLAGS_DIRTY)
einfo->flags |= CMAN_EXTRA_FLAG_DIRTY; einfo->flags |= CMAN_EXTRA_FLAG_DIRTY;
if (enable_disallowed) if (enable_disallowed)
einfo->flags |= CMAN_EXTRA_FLAG_DISALLOWED_ENABLED; einfo->flags |= CMAN_EXTRA_FLAG_DISALLOWED_ENABLED;
ptr = einfo->addresses; ptr = einfo->addresses;
corosync->object_find_create(OBJECT_PARENT_HANDLE, "totem", strlen(" totem"), &totem_find_handle); corosync->object_find_create(OBJECT_PARENT_HANDLE, "totem", strlen(" totem"), &totem_find_handle);
if (corosync->object_find_next(totem_find_handle, &totem_object_hand le) == 0) { if (corosync->object_find_next(totem_find_handle, &totem_object_hand le) == 0) {
corosync->object_find_destroy(totem_find_handle);
corosync->object_find_create(totem_object_handle, "interface ", strlen("interface"), &iface_find_handle); corosync->object_find_create(totem_object_handle, "interface ", strlen("interface"), &iface_find_handle);
while (corosync->object_find_next(iface_find_handle, &object _handle) == 0) { while (corosync->object_find_next(iface_find_handle, &object _handle) == 0) {
char *mcast; char *mcast;
struct sockaddr_in *saddr4; struct sockaddr_in *saddr4;
struct sockaddr_in6 *saddr6; struct sockaddr_in6 *saddr6;
objdb_get_string(corosync, object_handle, "mcastaddr ", &mcast); objdb_get_string(corosync, object_handle, "mcastaddr ", &mcast);
/* If this fails, it must be using broadcast*/ /* If this fails, it must be using broadcast*/
if (!mcast) if (!mcast)
skipping to change at line 591 skipping to change at line 589
saddr6 = (struct sockaddr_in6 *)ptr; saddr6 = (struct sockaddr_in6 *)ptr;
if ( inet_pton(AF_INET, mcast, &saddr4->sin_addr) >0 ) { if ( inet_pton(AF_INET, mcast, &saddr4->sin_addr) >0 ) {
saddr4->sin_family = AF_INET; saddr4->sin_family = AF_INET;
} }
else { else {
if (inet_pton(AF_INET6, mcast, &saddr6->sin6 _addr) > 0) if (inet_pton(AF_INET6, mcast, &saddr6->sin6 _addr) > 0)
saddr4->sin_family = AF_INET6; saddr4->sin_family = AF_INET6;
} }
ptr += sizeof(struct sockaddr_storage); ptr += sizeof(struct sockaddr_storage);
} }
corosync->object_find_destroy(iface_find_handle);
} }
corosync->object_find_destroy(iface_find_handle); corosync->object_find_destroy(totem_find_handle);
for (i=0; i<num_interfaces; i++) { for (i=0; i<num_interfaces; i++) {
ss = (struct sockaddr_storage *)ptr; ss = (struct sockaddr_storage *)ptr;
totemip_to_sockaddr(&node_ifs[i], 0, ss, &addrlen); totemip_to_sockaddr(&node_ifs[i], 0, ss, &addrlen);
ptr += sizeof(struct sockaddr_storage); ptr += sizeof(struct sockaddr_storage);
} }
*retlen = ptr - outbuf; *retlen = ptr - outbuf;
return 0; return 0;
} }
static int do_cmd_get_all_members(char *cmdbuf, char **retbuf, int retsize, int *retlen, int offset) static int do_cmd_get_all_members(char *cmdbuf, char **retbuf, int retsize, int *retlen, int offset)
{ {
struct cluster_node *node; struct cluster_node *node;
struct cl_cluster_node *user_node; struct cl_cluster_node *user_node;
struct list *nodelist; struct list *nodelist;
char *outbuf = *retbuf + offset; char *outbuf = *retbuf + offset;
int num_nodes = 0; int num_nodes = 0;
int total_nodes = 0; int total_nodes = 0;
int highest_node;
if (!we_are_a_cluster_member) if (!we_are_a_cluster_member)
return -ENOENT; return -ENOENT;
highest_node = get_highest_nodeid();
/* Count nodes */ /* Count nodes */
list_iterate(nodelist, &cluster_members_list) { list_iterate(nodelist, &cluster_members_list) {
total_nodes++; total_nodes++;
} }
if (quorum_device) if (quorum_device)
total_nodes++; total_nodes++;
/* if retsize == 0 then don't return node information */ /* if retsize == 0 then don't return node information */
if (retsize) { if (retsize) {
/* If there is not enough space in the default buffer, alloc ate some more. */ /* If there is not enough space in the default buffer, alloc ate some more. */
skipping to change at line 1402 skipping to change at line 1399
node->flags |= NODE_FLAGS_FENCED; node->flags |= NODE_FLAGS_FENCED;
if (node->state == NODESTATE_MEMBER) if (node->state == NODESTATE_MEMBER)
node->flags |= NODE_FLAGS_FENCEDWHILEUP; node->flags |= NODE_FLAGS_FENCEDWHILEUP;
/* Tell the rest of the cluster (and us!) */ /* Tell the rest of the cluster (and us!) */
fence_msg->cmd = CLUSTER_MSG_FENCESTATUS; fence_msg->cmd = CLUSTER_MSG_FENCESTATUS;
fence_msg->nodeid = f->nodeid; fence_msg->nodeid = f->nodeid;
fence_msg->timesec = f->fence_time; fence_msg->timesec = f->fence_time;
fence_msg->fenced = 1; fence_msg->fenced = 1;
strcpy(fence_msg->agent, f->fence_agent); strncpy(fence_msg->agent, f->fence_agent, MAX_FENCE_AGENT_NAME_LEN - 1);
comms_send_message(msg, sizeof(msg), 0,0, 0, 0); comms_send_message(msg, sizeof(msg), 0,0, 0, 0);
log_printf(LOGSYS_LEVEL_DEBUG, "memb: node %d fenced by %s\n", f->no deid, f->fence_agent); log_printf(LOGSYS_LEVEL_DEBUG, "memb: node %d fenced by %s\n", f->no deid, f->fence_agent);
return 0; return 0;
} }
static int do_cmd_get_fence_info(char *cmdbuf, char **retbuf, int retsize, int *retlen, int offset) static int do_cmd_get_fence_info(char *cmdbuf, char **retbuf, int retsize, int *retlen, int offset)
{ {
int nodeid; int nodeid;
char *outbuf = *retbuf + offset; char *outbuf = *retbuf + offset;
skipping to change at line 1429 skipping to change at line 1426
node = find_node_by_nodeid(nodeid); node = find_node_by_nodeid(nodeid);
if (!node) if (!node)
return -EINVAL; return -EINVAL;
f->nodeid = nodeid; f->nodeid = nodeid;
f->fence_time = node->fence_time; f->fence_time = node->fence_time;
f->flags = node->flags&NODE_FLAGS_FENCED; f->flags = node->flags&NODE_FLAGS_FENCED;
if (node->fence_agent) if (node->fence_agent)
strcpy(f->fence_agent, node->fence_agent); strncpy(f->fence_agent, node->fence_agent, MAX_FENCE_AGENT_N AME_LEN - 1);
else else
f->fence_agent[0] = '\0'; f->fence_agent[0] = '\0';
*retlen = sizeof(struct cl_fence_info); *retlen = sizeof(struct cl_fence_info);
return 0; return 0;
} }
static int do_cmd_get_node_addrs(char *cmdbuf, char **retbuf, int retsize, int *retlen, int offset) static int do_cmd_get_node_addrs(char *cmdbuf, char **retbuf, int retsize, int *retlen, int offset)
{ {
int nodeid; int nodeid;
int i; int i;
skipping to change at line 1865 skipping to change at line 1862
msg->votes = us->votes; msg->votes = us->votes;
msg->expected_votes = us->expected_votes; msg->expected_votes = us->expected_votes;
msg->cluster_id = cluster_id; msg->cluster_id = cluster_id;
msg->major_version = CNXMAN_MAJOR_VERSION; msg->major_version = CNXMAN_MAJOR_VERSION;
msg->minor_version = CNXMAN_MINOR_VERSION; msg->minor_version = CNXMAN_MINOR_VERSION;
msg->patch_version = CNXMAN_PATCH_VERSION; msg->patch_version = CNXMAN_PATCH_VERSION;
msg->config_version = config_version; msg->config_version = config_version;
msg->flags = us->flags; msg->flags = us->flags;
msg->fence_time = us->fence_time; msg->fence_time = us->fence_time;
msg->join_time = join_time; msg->join_time = join_time;
strcpy(msg->clustername, cluster_name); memcpy(msg->clustername, cluster_name, MAX_CLUSTER_NAME_LEN);
if (us->fence_agent) if (us->fence_agent)
{ {
strcpy(msg->fence_agent, us->fence_agent); strncpy(msg->fence_agent, us->fence_agent, MAX_FENCE_AGENT_N AME_LEN - 1);
len += strlen(us->fence_agent)+1; len += strlen(us->fence_agent)+1;
} }
else else
{ {
msg->fence_agent[0] = '\0'; msg->fence_agent[0] = '\0';
len += 1; len += 1;
} }
if (have_disallowed()) if (have_disallowed())
msg->flags |= NODE_FLAGS_SEESDISALLOWED; msg->flags |= NODE_FLAGS_SEESDISALLOWED;
comms_send_message(msg, len, comms_send_message(msg, len,
0,0, 0,0,
0, /* multicast */ 0, /* multicast */
0); /* flags */ 0); /* flags */
} }
static void byteswap_internal_message(char *data) static void byteswap_internal_message(char *data)
{ {
struct cl_protmsg *msg = (struct cl_protmsg *)data; struct cl_protmsg *msg = (struct cl_protmsg *)data;
struct cl_barriermsg *barriermsg;
struct cl_killmsg *killmsg; struct cl_killmsg *killmsg;
struct cl_leavemsg *leavemsg; struct cl_leavemsg *leavemsg;
struct cl_transmsg *transmsg; struct cl_transmsg *transmsg;
struct cl_fencemsg *fencemsg; struct cl_fencemsg *fencemsg;
struct cl_reconfig_msg *reconfmsg; struct cl_reconfig_msg *reconfmsg;
switch (msg->cmd) { switch (msg->cmd) {
case CLUSTER_MSG_PORTOPENED: case CLUSTER_MSG_PORTOPENED:
case CLUSTER_MSG_PORTCLOSED: case CLUSTER_MSG_PORTCLOSED:
/* Just a byte */ /* Just a byte */
skipping to change at line 1927 skipping to change at line 1923
killmsg->reason = swab16(killmsg->reason); killmsg->reason = swab16(killmsg->reason);
killmsg->nodeid = swab32(killmsg->nodeid); killmsg->nodeid = swab32(killmsg->nodeid);
break; break;
case CLUSTER_MSG_LEAVE: case CLUSTER_MSG_LEAVE:
leavemsg = (struct cl_leavemsg *)data; leavemsg = (struct cl_leavemsg *)data;
leavemsg->reason = swab16(leavemsg->reason); leavemsg->reason = swab16(leavemsg->reason);
break; break;
case CLUSTER_MSG_BARRIER: case CLUSTER_MSG_BARRIER:
barriermsg = (struct cl_barriermsg *)data;
break; break;
case CLUSTER_MSG_RECONFIGURE: case CLUSTER_MSG_RECONFIGURE:
reconfmsg = (struct cl_reconfig_msg *)data; reconfmsg = (struct cl_reconfig_msg *)data;
reconfmsg->nodeid = swab32(reconfmsg->nodeid); reconfmsg->nodeid = swab32(reconfmsg->nodeid);
reconfmsg->value = swab32(reconfmsg->value); reconfmsg->value = swab32(reconfmsg->value);
break; break;
case CLUSTER_MSG_FENCESTATUS: case CLUSTER_MSG_FENCESTATUS:
fencemsg = (struct cl_fencemsg *)data; fencemsg = (struct cl_fencemsg *)data;
skipping to change at line 2127 skipping to change at line 2122
if (node->fence_time && !msg->fence_time && if (node->fence_time && !msg->fence_time &&
node->fence_agent && !msg->fence_agent[0]) node->fence_agent && !msg->fence_agent[0])
{ {
char fencemsg[sizeof(struct cl_fencemsg)+strlen(node->fence_ agent)+1]; char fencemsg[sizeof(struct cl_fencemsg)+strlen(node->fence_ agent)+1];
struct cl_fencemsg *fence_msg = (struct cl_fencemsg *)fencem sg; struct cl_fencemsg *fence_msg = (struct cl_fencemsg *)fencem sg;
fence_msg->cmd = CLUSTER_MSG_FENCESTATUS; fence_msg->cmd = CLUSTER_MSG_FENCESTATUS;
fence_msg->nodeid = nodeid; fence_msg->nodeid = nodeid;
fence_msg->timesec = node->fence_time; fence_msg->timesec = node->fence_time;
fence_msg->fenced = 0; fence_msg->fenced = 0;
strcpy(fence_msg->agent, node->fence_agent); strncpy(fence_msg->agent, node->fence_agent, MAX_FENCE_AGENT _NAME_LEN - 1);
comms_send_message(fencemsg, sizeof(fencemsg), 0,0, nodeid, 0); comms_send_message(fencemsg, sizeof(fencemsg), 0,0, nodeid, 0);
} }
} }
static void process_internal_message(char *data, int nodeid, int need_bytes wap) static void process_internal_message(char *data, int nodeid, int need_bytes wap)
{ {
struct cl_protmsg *msg = (struct cl_protmsg *)data; struct cl_protmsg *msg = (struct cl_protmsg *)data;
struct cl_portmsg *portmsg; struct cl_portmsg *portmsg;
struct cl_barriermsg *barriermsg; struct cl_barriermsg *barriermsg;
struct cl_killmsg *killmsg; struct cl_killmsg *killmsg;
skipping to change at line 2306 skipping to change at line 2301
node = us; node = us;
log_printf(LOGSYS_LEVEL_DEBUG, "memb: Adding AIS node for 'u s'\n"); log_printf(LOGSYS_LEVEL_DEBUG, "memb: Adding AIS node for 'u s'\n");
} }
/* This really should exist!! */ /* This really should exist!! */
if (!node) { if (!node) {
char tempname[256]; char tempname[256];
log_printf(LOG_ERR, "Got node from AIS id %d with no config entry\n", nodeid); log_printf(LOG_ERR, "Got node from AIS id %d with no config entry\n", nodeid);
/* Emergency nodename */ /* Emergency nodename */
sprintf(tempname, "Node%d", nodeid); snprintf(tempname, sizeof(tempname) - 1, "Node%d", nodeid);
node = add_new_node(tempname, nodeid, 1, total_members, NODE STATE_DEAD); node = add_new_node(tempname, nodeid, 1, total_members, NODE STATE_DEAD);
if (!node) {
log_printf(LOG_ERR, "Unable to add newnode!\n");
return;
}
} }
if (node->state == NODESTATE_DEAD || node->state == NODESTATE_LEAVIN G) { if (node->state == NODESTATE_DEAD || node->state == NODESTATE_LEAVIN G) {
gettimeofday(&node->join_time, NULL); gettimeofday(&node->join_time, NULL);
node->incarnation = incar; node->incarnation = incar;
node->leave_reason = 0; node->leave_reason = 0;
/* If a node rejoins before it completes a leave, /* If a node rejoins before it completes a leave,
* we should not increment cluster_members */ * we should not increment cluster_members */
if (node->state != NODESTATE_LEAVING) if (node->state != NODESTATE_LEAVING)
cluster_members++; cluster_members++;
skipping to change at line 2376 skipping to change at line 2375
else else
recalculate_quorum(0, 0); recalculate_quorum(0, 0);
break; break;
case NODESTATE_JOINING: case NODESTATE_JOINING:
case NODESTATE_DEAD: case NODESTATE_DEAD:
break; break;
} }
} }
static int get_highest_nodeid()
{
int highest = 0;
struct cluster_node *node;
list_iterate_items(node, &cluster_members_list) {
if (node->node_id > highest)
highest = node->node_id;
}
return highest;
}
static int get_node_count() static int get_node_count()
{ {
int count = 0; int count = 0;
struct cluster_node *node; struct cluster_node *node;
list_iterate_items(node, &cluster_members_list) { list_iterate_items(node, &cluster_members_list) {
count++; count++;
} }
return count; return count;
skipping to change at line 2438 skipping to change at line 2425
case CLUSTER_KILL_REJECTED: case CLUSTER_KILL_REJECTED:
return "our membership application was rejected"; return "our membership application was rejected";
case CLUSTER_KILL_CMANTOOL: case CLUSTER_KILL_CMANTOOL:
return "we were killed by cman_tool or other application"; return "we were killed by cman_tool or other application";
case CLUSTER_KILL_REJOIN: case CLUSTER_KILL_REJOIN:
return "we rejoined the cluster without a full restart"; return "we rejoined the cluster without a full restart";
default: default:
sprintf(msg, "we got kill message number %d", reason); snprintf(msg, sizeof(msg) - 1, "we got kill message number % d", reason);
return msg; return msg;
} }
} }
 End of changes. 22 change blocks. 
34 lines changed or deleted 21 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/