On 10/20/2011 07:33 PM, MORITA Kazutaka wrote: > Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> > --- > sheep/group.c | 51 ++++++++++++++++++++++++++++++++++----------------- > 1 files changed, 34 insertions(+), 17 deletions(-) > > diff --git a/sheep/group.c b/sheep/group.c > index 7e4531d..04fec41 100644 > --- a/sheep/group.c > +++ b/sheep/group.c > @@ -49,8 +49,8 @@ struct join_message { > uint8_t inc_epoch; /* set non-zero when we increment epoch of all nodes */ > uint8_t pad[3]; > union { > - struct sheepdog_node_list_entry nodes[SD_MAX_NODES]; > - struct sheepdog_node_list_entry leave_nodes[SD_MAX_NODES]; > + struct sheepdog_node_list_entry nodes[0]; > + struct sheepdog_node_list_entry leave_nodes[0]; > }; > }; > > @@ -74,7 +74,7 @@ struct work_join { > size_t member_list_entries; > struct sheepdog_node_list_entry joined; > > - struct join_message jm; > + struct join_message *jm; > }; > > struct work_leave { > @@ -100,6 +100,13 @@ struct work_leave { > > static int cpg_event_running; > > +static size_t get_join_message_size(struct join_message *jm) > +{ > + /* jm->nr_nodes is always larger than jm->nr_leave_nodes, so > + * it is safe to use jm->nr_nodes. */ > + return sizeof(*jm) + jm->nr_nodes * sizeof(jm->nodes[0]); > +} > + > static int get_node_idx(struct sheepdog_node_list_entry *ent, > struct sheepdog_node_list_entry *entries, int nr_nodes) > { > @@ -863,7 +870,7 @@ static int check_majority(struct sheepdog_node_list_entry *nodes, int nr_nodes) > static void __sd_join(struct cpg_event *cevent) > { > struct work_join *w = container_of(cevent, struct work_join, cev); > - struct join_message *msg = &w->jm; > + struct join_message *msg = w->jm; > int i; > > if (msg->cluster_status != SD_STATUS_OK) > @@ -953,23 +960,29 @@ static enum cluster_join_result sd_check_join_cb( > > static int send_join_request(struct sheepdog_node_list_entry *ent) > { > - struct join_message msg; > + struct join_message *msg; > int nr_entries, ret; > > - memset(&msg, 0, sizeof(msg)); > - msg.header.proto_ver = SD_SHEEP_PROTO_VER; > - msg.header.msg_length = sizeof(msg); > - msg.header.from = *ent; > + msg = zalloc(sizeof(*msg) * SD_MAX_NODES * sizeof(msg->nodes[0])); zalloc(sizeof(*msg) + ...) ? Yuan |