Commit 695b9225 authored by Shane Snyder's avatar Shane Snyder

bunch of mods on group descriptors & locking

parent 03a3135f
......@@ -28,8 +28,8 @@ extern "C" {
#define SSG_FAILURE (-1)
/* opaque SSG group ID type */
typedef struct ssg_group_descriptor *ssg_group_id_t;
#define SSG_GROUP_ID_NULL ((ssg_group_id_t)NULL)
typedef uint64_t ssg_group_id_t;
#define SSG_GROUP_ID_INVALID 0
/* SSG group member ID type */
typedef uint64_t ssg_member_id_t;
......@@ -49,8 +49,8 @@ typedef void (*ssg_membership_update_cb)(
ssg_member_update_type_t update_type);
/* HG proc routine prototypes for SSG types */
#define hg_proc_ssg_member_id_t hg_proc_int64_t
hg_return_t hg_proc_ssg_group_id_t(hg_proc_t proc, void *data);
#define hg_proc_ssg_group_id_t hg_proc_uint64_t
#define hg_proc_ssg_member_id_t hg_proc_uint64_t
/***************************************************
*** SSG runtime intialization/shutdown routines ***
......@@ -209,22 +209,6 @@ hg_addr_t ssg_get_group_addr(
ssg_group_id_t group_id,
ssg_member_id_t member_id);
/**
* Duplicates the given SSG group identifier.
*
* @param[in] group_id SSG group ID
* @returns SSG group identifier on success, SSG_GROUP_ID_NULL otherwise
*/
ssg_group_id_t ssg_group_id_dup(
ssg_group_id_t group_id);
/** Frees the given SSG group identifier.
*
* @param[in] group_id SSG group ID
*/
void ssg_group_id_free(
ssg_group_id_t group_id);
/**
* Retrieves the HG address string associated with an SSG group identifier.
*
......
......@@ -47,22 +47,24 @@ typedef struct ssg_instance
margo_instance_id mid;
char *self_addr_str;
ssg_member_id_t self_id;
struct ssg_group *group_table;
struct ssg_group_descriptor *g_desc_table;
#if 0
struct ssg_attached_group *attached_group_table;
#endif
#ifdef SSG_HAVE_PMIX
size_t pmix_failure_evhdlr_ref;
#endif
ABT_rwlock lock;
} ssg_instance_t;
/* TODO: associate a version number with a descriptor? */
typedef struct ssg_group_descriptor
{
uint64_t magic_nr;
uint64_t name_hash;
ssg_group_id_t g_id;
char *addr_str;
int owner_status;
int ref_count;
struct ssg_group *g;
UT_hash_handle hh;
} ssg_group_descriptor_t;
enum ssg_group_descriptor_owner_status
......@@ -101,7 +103,6 @@ typedef struct ssg_group
#ifdef DEBUG
FILE *dbg_log;
#endif
UT_hash_handle hh;
} ssg_group_t;
typedef struct ssg_attached_group
......@@ -111,7 +112,6 @@ typedef struct ssg_attached_group
ssg_group_view_t view;
ssg_group_descriptor_t *descriptor;
ABT_rwlock lock;
UT_hash_handle hh;
} ssg_attached_group_t;
typedef struct ssg_member_update
......
......@@ -24,9 +24,9 @@
/* NOTE: keep in sync with ssg_group_descriptor_t definition in ssg-internal.h */
MERCURY_GEN_STRUCT_PROC(ssg_group_descriptor_t, \
((uint64_t) (magic_nr)) \
((uint64_t) (name_hash)) \
((hg_string_t) (addr_str)));
((uint64_t) (magic_nr)) \
((ssg_group_id_t) (g_id)) \
((hg_string_t) (addr_str)));
MERCURY_GEN_PROC(ssg_group_join_request_t, \
((ssg_group_descriptor_t) (group_descriptor))
......@@ -36,7 +36,7 @@ MERCURY_GEN_PROC(ssg_group_join_response_t, \
((hg_string_t) (group_name)) \
((uint32_t) (group_size)) \
((hg_size_t) (view_buf_size))
((uint8_t) (ret)));
((uint8_t) (ret)));
MERCURY_GEN_PROC(ssg_group_leave_request_t, \
((ssg_group_descriptor_t) (group_descriptor))
......@@ -201,7 +201,7 @@ static void ssg_group_join_recv_ult(
hg_handle_t handle)
{
const struct hg_info *hgi = NULL;
ssg_group_t *g = NULL;
ssg_group_descriptor_t *g_desc = NULL;
ssg_group_join_request_t join_req;
ssg_group_join_response_t join_resp;
hg_size_t view_size_requested;
......@@ -224,15 +224,15 @@ static void ssg_group_join_recv_ult(
view_size_requested = margo_bulk_get_size(join_req.bulk_handle);
/* look for the given group in my local table of groups */
HASH_FIND(hh, ssg_inst->group_table, &join_req.group_descriptor.name_hash,
sizeof(uint64_t), g);
if (!g)
HASH_FIND(hh, ssg_inst->g_desc_table, &join_req.group_descriptor.g_id,
sizeof(uint64_t), g_desc);
if (!g_desc)
{
margo_free_input(handle, &join_req);
goto fini;
}
sret = ssg_group_serialize(g, &view_buf, &view_buf_size);
sret = ssg_group_serialize(g_desc->g, &view_buf, &view_buf_size);
if (sret != SSG_SUCCESS)
{
margo_free_input(handle, &join_req);
......@@ -261,13 +261,13 @@ static void ssg_group_join_recv_ult(
/* apply group join locally */
join_update.type = SSG_MEMBER_JOINED;
join_update.u.member_addr_str = join_req.addr_str;
ssg_apply_member_updates(g, &join_update, 1);
ssg_apply_member_updates(g_desc->g, &join_update, 1);
}
margo_free_input(handle, &join_req);
/* set the response and send back */
join_resp.group_name = g->name;
join_resp.group_size = (int)g->view.size;
join_resp.group_name = g_desc->g->name;
join_resp.group_size = (int)g_desc->g->view.size;
join_resp.view_buf_size = view_buf_size;
join_resp.ret = SSG_SUCCESS;
fini:
......@@ -324,7 +324,7 @@ static void ssg_group_leave_recv_ult(
hg_handle_t handle)
{
const struct hg_info *hgi = NULL;
ssg_group_t *g = NULL;
ssg_group_descriptor_t *g_desc = NULL;
ssg_group_leave_request_t leave_req;
ssg_group_leave_response_t leave_resp;
ssg_member_update_t leave_update;
......@@ -341,9 +341,9 @@ static void ssg_group_leave_recv_ult(
if (hret != HG_SUCCESS) goto fini;
/* look for the given group in my local table of groups */
HASH_FIND(hh, ssg_inst->group_table, &leave_req.group_descriptor.name_hash,
sizeof(uint64_t), g);
if (!g)
HASH_FIND(hh, ssg_inst->g_desc_table, &leave_req.group_descriptor.g_id,
sizeof(uint64_t), g_desc);
if (!g_desc)
{
margo_free_input(handle, &leave_req);
goto fini;
......@@ -352,7 +352,7 @@ static void ssg_group_leave_recv_ult(
/* apply group leave locally */
leave_update.type = SSG_MEMBER_LEFT;
leave_update.u.member_id = leave_req.member_id;
ssg_apply_member_updates(g, &leave_update, 1);
ssg_apply_member_updates(g_desc->g, &leave_update, 1);
margo_free_input(handle, &leave_req);
leave_resp.ret = SSG_SUCCESS;
......@@ -482,7 +482,7 @@ static void ssg_group_attach_recv_ult(
hg_handle_t handle)
{
const struct hg_info *hgi = NULL;
ssg_group_t *g = NULL;
ssg_group_descriptor_t *g_desc = NULL;
ssg_group_attach_request_t attach_req;
ssg_group_attach_response_t attach_resp;
hg_size_t view_size_requested;
......@@ -502,15 +502,15 @@ static void ssg_group_attach_recv_ult(
view_size_requested = margo_bulk_get_size(attach_req.bulk_handle);
/* look for the given group in my local table of groups */
HASH_FIND(hh, ssg_inst->group_table, &attach_req.group_descriptor.name_hash,
sizeof(uint64_t), g);
if (!g)
HASH_FIND(hh, ssg_inst->g_desc_table, &attach_req.group_descriptor.g_id,
sizeof(uint64_t), g_desc);
if (!g_desc)
{
margo_free_input(handle, &attach_req);
goto fini;
}
sret = ssg_group_serialize(g, &view_buf, &view_buf_size);
sret = ssg_group_serialize(g_desc->g, &view_buf, &view_buf_size);
if (sret != SSG_SUCCESS)
{
margo_free_input(handle, &attach_req);
......@@ -538,8 +538,8 @@ static void ssg_group_attach_recv_ult(
}
/* set the response and send back */
attach_resp.group_name = g->name;
attach_resp.group_size = (int)g->view.size;
attach_resp.group_name = g_desc->g->name;
attach_resp.group_size = (int)g_desc->g->view.size;
attach_resp.view_buf_size = view_buf_size;
margo_respond(handle, &attach_resp);
......@@ -564,6 +564,8 @@ static int ssg_group_serialize(
*buf = NULL;
*buf_size = 0;
ABT_rwlock_rdlock(g->lock);
/* first determine size */
group_buf_size = strlen(ssg_inst->self_addr_str) + 1;
HASH_ITER(hh, g->view.member_map, member_state, tmp)
......@@ -574,6 +576,7 @@ static int ssg_group_serialize(
group_buf = malloc(group_buf_size);
if(!group_buf)
{
ABT_rwlock_unlock(g->lock);
return SSG_FAILURE;
}
......@@ -590,62 +593,13 @@ static int ssg_group_serialize(
*buf = group_buf;
*buf_size = group_buf_size;
ABT_rwlock_unlock(g->lock);
return SSG_SUCCESS;
}
/* custom SSG RPC proc routines */
hg_return_t hg_proc_ssg_group_id_t(
hg_proc_t proc, void *data)
{
ssg_group_descriptor_t **group_descriptor = (ssg_group_descriptor_t **)data;
hg_return_t hret = HG_PROTOCOL_ERROR;
switch(hg_proc_get_op(proc))
{
case HG_ENCODE:
hret = hg_proc_ssg_group_descriptor_t(proc, *group_descriptor);
if (hret != HG_SUCCESS)
{
hret = HG_PROTOCOL_ERROR;
return hret;
}
break;
case HG_DECODE:
*group_descriptor = malloc(sizeof(**group_descriptor));
if (!(*group_descriptor))
{
hret = HG_NOMEM_ERROR;
return hret;
}
memset(*group_descriptor, 0, sizeof(**group_descriptor));
hret = hg_proc_ssg_group_descriptor_t(proc, *group_descriptor);
if (hret != HG_SUCCESS)
{
hret = HG_PROTOCOL_ERROR;
return hret;
}
(*group_descriptor)->ref_count = 1;
break;
case HG_FREE:
if ((*group_descriptor)->ref_count == 1)
{
free((*group_descriptor)->addr_str);
free(*group_descriptor);
}
else
{
(*group_descriptor)->ref_count--;
}
hret = HG_SUCCESS;
break;
default:
break;
}
return hret;
}
hg_return_t hg_proc_ssg_member_update_t(
hg_proc_t proc, void *data)
{
......
......@@ -48,7 +48,7 @@ struct ssg_group_lookup_ult_args
static void ssg_group_lookup_ult(void * arg);
/* SSG helper routine prototypes */
static ssg_group_t * ssg_group_create_internal(
static ssg_group_id_t ssg_group_create_internal(
const char * group_name, const char * const group_addr_strs[],
int group_size, ssg_membership_update_cb update_cb, void *update_cb_dat);
static int ssg_group_view_create(
......@@ -59,9 +59,7 @@ static ssg_member_state_t * ssg_group_view_add_member(
const char * addr_str, hg_addr_t addr, ssg_member_id_t member_id,
ssg_group_view_t * view);
static ssg_group_descriptor_t * ssg_group_descriptor_create(
uint64_t name_hash, const char * leader_addr_str, int owner_status);
static ssg_group_descriptor_t * ssg_group_descriptor_dup(
ssg_group_descriptor_t * descriptor);
ssg_group_id_t g_id, const char * leader_addr_str, int owner_status);
static void ssg_group_destroy_internal(
ssg_group_t * g);
static void ssg_attached_group_destroy(
......@@ -148,35 +146,41 @@ int ssg_init(
int ssg_finalize()
{
ssg_group_t *g, *g_tmp;
ssg_group_descriptor_t *g_desc, *g_desc_tmp;
#if 0
ssg_attached_group_t *ag, *ag_tmp;
#endif
if (!ssg_inst)
return SSG_FAILURE;
ABT_rwlock_wrlock(ssg_inst->lock);
#ifdef SSG_HAVE_PMIX
if (ssg_inst->pmix_failure_evhdlr_ref)
PMIx_Deregister_event_handler(ssg_inst->pmix_failure_evhdlr_ref, NULL, NULL);
#endif
/* destroy all active groups */
HASH_ITER(hh, ssg_inst->group_table, g, g_tmp)
ABT_rwlock_wrlock(ssg_inst->lock);
HASH_ITER(hh, ssg_inst->g_desc_table, g_desc, g_desc_tmp)
{
HASH_DELETE(hh, ssg_inst->group_table, g);
HASH_DELETE(hh, ssg_inst->g_desc_table, g_desc);
ABT_rwlock_unlock(ssg_inst->lock);
ssg_group_destroy_internal(g);
ssg_group_destroy_internal(g_desc->g);
ssg_group_descriptor_free(g_desc);
ABT_rwlock_wrlock(ssg_inst->lock);
}
ABT_rwlock_unlock(ssg_inst->lock);
#if 0
/* detach from all attached groups */
HASH_ITER(hh, ssg_inst->attached_group_table, ag, ag_tmp)
{
HASH_DELETE(hh, ssg_inst->attached_group_table, ag);
ssg_attached_group_destroy(ag);
}
#endif
#ifdef SSG_HAVE_PMIX
if (ssg_inst->pmix_failure_evhdlr_ref)
PMIx_Deregister_event_handler(ssg_inst->pmix_failure_evhdlr_ref, NULL, NULL);
#endif
ABT_rwlock_unlock(ssg_inst->lock);
ABT_rwlock_free(&ssg_inst->lock);
free(ssg_inst->self_addr_str);
......@@ -197,13 +201,10 @@ ssg_group_id_t ssg_group_create(
ssg_membership_update_cb update_cb,
void * update_cb_dat)
{
ssg_group_t *g;
ssg_group_id_t g_id = SSG_GROUP_ID_NULL;
ssg_group_id_t g_id;
g = ssg_group_create_internal(group_name, group_addr_strs,
g_id = ssg_group_create_internal(group_name, group_addr_strs,
group_size, update_cb, update_cb_dat);
if (g)
g_id = (ssg_group_id_t)g->descriptor;
return g_id;
}
......@@ -223,7 +224,7 @@ ssg_group_id_t ssg_group_create_config(
int addr_str_buf_len = 0, num_addrs = 0;
const char **addr_strs = NULL;
int ret;
ssg_group_id_t group_id = SSG_GROUP_ID_NULL;
ssg_group_id_t g_id = SSG_GROUP_ID_INVALID;
/* open config file for reading */
fd = open(file_name, O_RDONLY);
......@@ -285,7 +286,7 @@ ssg_group_id_t ssg_group_create_config(
if (!addr_strs) goto fini;
/* invoke the generic group create routine using our list of addrs */
group_id = ssg_group_create(group_name, addr_strs, num_addrs,
g_id = ssg_group_create(group_name, addr_strs, num_addrs,
update_cb, update_cb_dat);
fini:
......@@ -295,7 +296,7 @@ fini:
free(addr_str_buf);
free(addr_strs);
return group_id;
return g_id;
}
#ifdef SSG_HAVE_MPI
......@@ -312,7 +313,7 @@ ssg_group_id_t ssg_group_create_mpi(
int *sizes_psum = NULL;
int comm_size = 0, comm_rank = 0;
const char **addr_strs = NULL;
ssg_group_id_t group_id = SSG_GROUP_ID_NULL;
ssg_group_id_t g_id = SSG_GROUP_ID_INVALID;
if (!ssg_inst) goto fini;
......@@ -345,7 +346,7 @@ ssg_group_id_t ssg_group_create_mpi(
if (!addr_strs) goto fini;
/* invoke the generic group create routine using our list of addrs */
group_id = ssg_group_create(group_name, addr_strs, comm_size,
g_id = ssg_group_create(group_name, addr_strs, comm_size,
update_cb, update_cb_dat);
fini:
......@@ -355,7 +356,7 @@ fini:
free(addr_str_buf);
free(addr_strs);
return group_id;
return g_id;
}
#endif
......@@ -377,7 +378,7 @@ ssg_group_id_t ssg_group_create_pmix(
const char **addr_strs = NULL;
unsigned int n;
pmix_status_t ret;
ssg_group_id_t group_id = SSG_GROUP_ID_NULL;
ssg_group_id_t g_id = SSG_GROUP_ID_INVALID;
if (!ssg_inst || !PMIx_Initialized()) goto fini;
......@@ -455,7 +456,7 @@ ssg_group_id_t ssg_group_create_pmix(
}
/* invoke the generic group create routine using our list of addrs */
group_id = ssg_group_create(group_name, addr_strs, nprocs,
g_id = ssg_group_create(group_name, addr_strs, nprocs,
update_cb, update_cb_dat);
fini:
......@@ -463,42 +464,39 @@ fini:
free(addr_strs);
PMIX_VALUE_FREE(addr_vals, nprocs);
return group_id;
return g_id;
}
#endif
int ssg_group_destroy(
ssg_group_id_t group_id)
{
ssg_group_descriptor_t *group_descriptor = (ssg_group_descriptor_t *)group_id;
ssg_group_t *g;
ssg_group_descriptor_t *g_desc;
if (!ssg_inst || group_id == SSG_GROUP_ID_NULL) return SSG_FAILURE;
if (group_descriptor->owner_status != SSG_OWNER_IS_MEMBER)
{
fprintf(stderr, "Error: SSG unable to destroy a group it is not a member of\n");
return SSG_FAILURE;
}
if (!ssg_inst || group_id == SSG_GROUP_ID_INVALID) return SSG_FAILURE;
ABT_rwlock_wrlock(ssg_inst->lock);
/* find the group structure and destroy it */
HASH_FIND(hh, ssg_inst->group_table, &group_descriptor->name_hash,
sizeof(uint64_t), g);
if (!g)
HASH_FIND(hh, ssg_inst->g_desc_table, &group_id, sizeof(ssg_group_id_t), g_desc);
if (!g_desc)
{
ABT_rwlock_unlock(ssg_inst->lock);
fprintf(stderr, "Error: SSG unable to find expected group reference\n");
fprintf(stderr, "Error: SSG unable to find expected group ID\n");
return SSG_FAILURE;
}
HASH_DELETE(hh, ssg_inst->group_table, g);
HASH_DELETE(hh, ssg_inst->g_desc_table, g_desc);
ABT_rwlock_unlock(ssg_inst->lock);
ssg_group_destroy_internal(g);
/* destroy the group, free the descriptor */
ssg_group_destroy_internal(g_desc->g);
ssg_group_descriptor_free(g_desc);
return SSG_SUCCESS;
}
#if 0
ssg_group_id_t ssg_group_join(
ssg_group_id_t in_group_id,
ssg_membership_update_cb update_cb,
......@@ -630,7 +628,6 @@ fini:
return sret;
}
#if 0
int ssg_group_attach(
ssg_group_id_t group_id)
{
......@@ -745,25 +742,27 @@ ssg_member_id_t ssg_get_self_id(
int ssg_get_group_size(
ssg_group_id_t group_id)
{
ssg_group_descriptor_t *group_descriptor = (ssg_group_descriptor_t *)group_id;
ssg_group_descriptor_t *g_desc;
int group_size = 0;
if (!ssg_inst || group_id == SSG_GROUP_ID_NULL) return 0;
if (!ssg_inst || group_id == SSG_GROUP_ID_INVALID) return 0;
if (group_descriptor->owner_status == SSG_OWNER_IS_MEMBER)
{
ssg_group_t *g;
ABT_rwlock_rdlock(ssg_inst->lock);
ABT_rwlock_rdlock(ssg_inst->lock);
HASH_FIND(hh, ssg_inst->group_table, &group_descriptor->name_hash,
sizeof(uint64_t), g);
if (g)
{
ABT_rwlock_rdlock(g->lock);
group_size = g->view.size + 1; /* add ourself to view size */
ABT_rwlock_unlock(g->lock);
}
/* find the group descriptor */
HASH_FIND(hh, ssg_inst->g_desc_table, &group_id, sizeof(ssg_group_id_t), g_desc);
if (!g_desc)
{
ABT_rwlock_unlock(ssg_inst->lock);
fprintf(stderr, "Error: SSG unable to find expected group ID\n");
return 0;
}
if (g_desc->owner_status == SSG_OWNER_IS_MEMBER)
{
ABT_rwlock_rdlock(g_desc->g->lock);
group_size = g_desc->g->view.size + 1; /* add ourself to view size */
ABT_rwlock_unlock(g_desc->g->lock);
}
#if 0
else if (group_descriptor->owner_status == SSG_OWNER_IS_ATTACHER)
......@@ -784,9 +783,10 @@ int ssg_get_group_size(
{
fprintf(stderr, "Error: SSG can only obtain size of groups that the caller" \
" is a member of or an attacher of\n");
return 0;
}
ABT_rwlock_unlock(ssg_inst->lock);
return group_size;
}
......@@ -794,31 +794,33 @@ hg_addr_t ssg_get_group_addr(
ssg_group_id_t group_id,
ssg_member_id_t member_id)
{
ssg_group_descriptor_t *group_descriptor = (ssg_group_descriptor_t *)group_id;
ssg_group_descriptor_t *g_desc;
ssg_member_state_t *member_state;
hg_addr_t member_addr = HG_ADDR_NULL;
if (!ssg_inst || group_id == SSG_GROUP_ID_NULL ||
if (!ssg_inst || group_id == SSG_GROUP_ID_INVALID ||
member_id == SSG_MEMBER_ID_INVALID)
return HG_ADDR_NULL;
if (group_descriptor->owner_status == SSG_OWNER_IS_MEMBER)
{
ssg_group_t *g;
ABT_rwlock_rdlock(ssg_inst->lock);
ABT_rwlock_rdlock(ssg_inst->lock);
HASH_FIND(hh, ssg_inst->group_table, &group_descriptor->name_hash,
sizeof(uint64_t), g);
if (g)
{
ABT_rwlock_rdlock(g->lock);
HASH_FIND(hh, g->view.member_map, &member_id, sizeof(ssg_member_id_t),
member_state);
if (member_state)
member_addr = member_state->addr;
ABT_rwlock_unlock(g->lock);
}
/* find the group descriptor */
HASH_FIND(hh, ssg_inst->g_desc_table, &group_id, sizeof(ssg_group_id_t), g_desc);
if (!g_desc)
{
ABT_rwlock_unlock(ssg_inst->lock);
fprintf(stderr, "Error: SSG unable to find expected group ID\n");
return HG_ADDR_NULL;
}
if (g_desc->owner_status == SSG_OWNER_IS_MEMBER)
{
ABT_rwlock_rdlock(g_desc->g->lock);
HASH_FIND(hh, g_desc->g->view.member_map, &member_id,
sizeof(ssg_member_id_t), member_state);
if (member_state)
member_addr = member_state->addr;
ABT_rwlock_unlock(g_desc->g->lock);
}
#if 0
else if (group_descriptor->owner_status == SSG_OWNER_IS_ATTACHER)
......@@ -842,37 +844,37 @@ hg_addr_t ssg_get_group_addr(
{
fprintf(stderr, "Error: SSG can only obtain member addresses of groups" \
" that the caller is a member of or an attacher of\n");
return HG_ADDR_NULL;
}
ABT_rwlock_unlock(ssg_inst->lock);
return member_addr;
}
ssg_group_id_t ssg_group_id_dup(
char *ssg_group_id_get_addr_str(
ssg_group_id_t group_id)
{
ssg_group_descriptor_t *dup;
ssg_group_descriptor_t *g_desc;
char *addr_str;
dup = ssg_group_descriptor_dup((ssg_group_descriptor_t *)group_id);
return (ssg_group_id_t)dup;
}
if (!ssg_inst || group_id == SSG_GROUP_ID_INVALID) return 0;
void ssg_group_id_free(
ssg_group_id_t group_id)
{
ssg_group_descriptor_t *descriptor = (ssg_group_descriptor_t *)group_id;
ABT_rwlock_rdlock(ssg_inst->lock);
ssg_group_descriptor_free(descriptor);
descriptor = SSG_GROUP_ID_NULL;
return;
}
/* find the group descriptor */
HASH_FIND(hh, ssg_inst->g_desc_table, &group_id, sizeof(ssg_group_id_t), g_desc);
if (!g_desc)
{
ABT_rwlock_unlock(ssg_inst->lock);
fprintf(stderr, "Error: SSG unable to find expected group ID\n");
return NULL;
}
char *ssg_group_id_get_addr_str(
ssg_group_id_t group_id)
{
ssg_group_descriptor_t *group_descriptor = (ssg_group_descriptor_t *)group_id;
addr_str = strdup(g_desc->addr_str);
return strdup(group_descriptor->addr_str);
ABT_rwlock_unlock(ssg_inst->lock);
return addr_str;
}
void ssg_group_id_serialize(
......@@ -880,16 +882,29 @@ void ssg_group_id_serialize(
char ** buf_p,
size_t * buf_size_p)
{
ssg_group_descriptor_t *group_descriptor = (ssg_group_descriptor_t *)group_id;
ssg_group_descriptor_t *g_desc;
size_t alloc_size;
char *gid_buf, *p;
*buf_p = NULL;
*buf_size_p = 0;
if (!ssg_inst || group_id == SSG_GROUP_ID_INVALID) return;
ABT_rwlock_rdlock(ssg_inst->lock);
/* find the group descriptor */
HASH_FIND(hh, ssg_inst->g_desc_table, &group_id, sizeof(ssg_group_id_t), g_desc);
if (!g_desc)
{
ABT_rwlock_unlock(ssg_inst->lock);
fprintf(stderr, "Error: SSG unable to find expected group ID\n");
return;
}
/* determine needed buffer size */
alloc_size = (sizeof(group_descriptor->magic_nr) + sizeof(group_descriptor->name_hash) +
strlen(group_descriptor->addr_str) + 1);
alloc_size = (sizeof(g_desc->magic_nr) + sizeof(g_desc->g_id) +
strlen(g_desc->addr_str) + 1);
gid_buf = malloc(alloc_size);
if (!gid_buf)
......@@ -897,13 +912,15 @@ void ssg_group_id_serialize(
/* serialize */
p = gid_buf;
*(uint64_t *)p = group_descriptor->magic_nr;
p += sizeof(uint64_t);
*(uint64_t *)p = group_descriptor->name_hash;
*(uint64_t *)p = g_desc->magic_nr;
p += sizeof(uint64_t);
strcpy(p, group_descriptor->addr_str);
*(ssg_group_id_t *)p = g_desc->g_id;
p += sizeof(ssg_group_id_t);
strcpy(p, g_desc->addr_str);
/* the rest of the descriptor is stateful and not appropriate for serializing... */
ABT_rwlock_unlock(ssg_inst->lock);
*buf_p = gid_buf;
*buf_size_p = alloc_size;
......@@ -917,15 +934,16 @@ void ssg_group_id_deserialize(
{
size_t min_buf_size;
uint64_t magic_nr;
uint64_t name_hash;
ssg_group_id_t g_id;
const char *addr_str;
ssg_group_descriptor_t *group_descriptor;
ssg_group_descriptor_t *g_desc;