Commit 4bcd8bc0 authored by Matthieu Dorier's avatar Matthieu Dorier

better error codes

parent 5ad48645
......@@ -26,6 +26,16 @@ typedef struct {
char data[BAKE_REGION_ID_DATA_SIZE];
} bake_region_id_t;
#define BAKE_SUCCESS 0 /* Success */
#define BAKE_ERR_ALLOCATION (-1) /* Error allocating something */
#define BAKE_ERR_INVALID_ARG (-2) /* An argument is invalid */
#define BAKE_ERR_MERCURY (-3) /* An error happened calling a Mercury function */
#define BAKE_ERR_ARGOBOTS (-4) /* An error happened calling an Argobots function */
#define BAKE_ERR_PMEM (-5) /* An error happened calling a pmem function */
#define BAKE_ERR_UNKNOWN_TARGET (-6) /* Target refered to by id is not known to provider */
#define BAKE_ERR_UNKNOWN_PROVIDER (-7) /* Provider id could not be matched with a provider */
#define BAKE_ERR_UNKNOWN_REGION (-8) /* Region id could not be found */
#ifdef __cplusplus
}
#endif
......
......@@ -110,21 +110,21 @@ static int bake_client_register(bake_client_t client, margo_instance_id mid)
bake_remove_in_t, bake_remove_out_t, NULL);
}
return(0);
return BAKE_SUCCESS;
}
int bake_client_init(margo_instance_id mid, bake_client_t* client)
{
bake_client_t c = (bake_client_t)calloc(1, sizeof(*c));
if(!c) return -1;
if(!c) return BAKE_ERR_ALLOCATION;
c->num_provider_handles = 0;
int ret = bake_client_register(c, mid);
if(ret != 0) return ret;
if(ret != BAKE_SUCCESS) return ret;
*client = c;
return 0;
return BAKE_SUCCESS;
}
int bake_client_finalize(bake_client_t client)
......@@ -135,7 +135,7 @@ int bake_client_finalize(bake_client_t client)
client->num_provider_handles);
}
free(client);
return 0;
return BAKE_SUCCESS;
}
int bake_probe(
......@@ -160,18 +160,18 @@ int bake_probe(
provider->client->bake_probe_id,
&handle);
if(hret != HG_SUCCESS) return -1;
if(hret != HG_SUCCESS) return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS) {
margo_destroy(handle);
return -1;
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS) {
margo_destroy(handle);
return -1;
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -200,17 +200,17 @@ int bake_provider_handle_create(
uint16_t provider_id,
bake_provider_handle_t* handle)
{
if(client == BAKE_CLIENT_NULL) return -1;
if(client == BAKE_CLIENT_NULL) return BAKE_ERR_INVALID_ARG;
bake_provider_handle_t provider =
(bake_provider_handle_t)calloc(1, sizeof(*provider));
if(!provider) return -1;
if(!provider) return BAKE_ERR_ALLOCATION;
hg_return_t ret = margo_addr_dup(client->mid, addr, &(provider->addr));
if(ret != HG_SUCCESS) {
free(provider);
return -1;
return BAKE_ERR_MERCURY;
}
provider->client = client;
......@@ -221,40 +221,40 @@ int bake_provider_handle_create(
client->num_provider_handles += 1;
*handle = provider;
return 0;
return BAKE_SUCCESS;
}
int bake_provider_handle_get_eager_limit(bake_provider_handle_t handle, uint64_t* limit)
{
if(handle == BAKE_PROVIDER_HANDLE_NULL) return -1;
if(handle == BAKE_PROVIDER_HANDLE_NULL) return BAKE_ERR_INVALID_ARG;
*limit = handle->eager_limit;
return 0;
return BAKE_SUCCESS;
}
int bake_provider_handle_set_eager_limit(bake_provider_handle_t handle, uint64_t limit)
{
if(handle == BAKE_PROVIDER_HANDLE_NULL) return -1;
if(handle == BAKE_PROVIDER_HANDLE_NULL) return BAKE_ERR_INVALID_ARG;
handle->eager_limit = limit;
return 0;
return BAKE_SUCCESS;
}
int bake_provider_handle_ref_incr(bake_provider_handle_t handle)
{
if(handle == BAKE_PROVIDER_HANDLE_NULL) return -1;
if(handle == BAKE_PROVIDER_HANDLE_NULL) return BAKE_ERR_INVALID_ARG;
handle->refcount += 1;
return 0;
return BAKE_SUCCESS;
}
int bake_provider_handle_release(bake_provider_handle_t handle)
{
if(handle == BAKE_PROVIDER_HANDLE_NULL) return -1;
if(handle == BAKE_PROVIDER_HANDLE_NULL) return BAKE_ERR_INVALID_ARG;
handle->refcount -= 1;
if(handle->refcount == 0) {
margo_addr_free(handle->client->mid, handle->addr);
handle->client->num_provider_handles -= 1;
free(handle);
}
return 0;
return BAKE_SUCCESS;
}
int bake_shutdown_service(bake_client_t client, hg_addr_t addr)
......@@ -284,20 +284,20 @@ static int bake_eager_write(
provider->client->bake_eager_write_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -305,7 +305,7 @@ static int bake_eager_write(
margo_free_output(handle, &out);
margo_destroy(handle);
return(ret);
return ret;
}
int bake_write(
......@@ -333,7 +333,7 @@ int bake_write(
hret = margo_bulk_create(provider->client->mid, 1, (void**)(&buf), &buf_size,
HG_BULK_READ_ONLY, &in.bulk_handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_create(provider->client->mid, provider->addr,
provider->client->bake_write_id, &handle);
......@@ -341,7 +341,7 @@ int bake_write(
if(hret != HG_SUCCESS)
{
margo_bulk_free(in.bulk_handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_provider_forward(provider->provider_id, handle, &in);
......@@ -349,7 +349,7 @@ int bake_write(
{
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
......@@ -357,7 +357,7 @@ int bake_write(
{
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -365,7 +365,7 @@ int bake_write(
margo_free_output(handle, &out);
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
return(ret);
return ret;
}
int bake_proxy_write(
......@@ -394,20 +394,20 @@ int bake_proxy_write(
provider->client->bake_write_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -436,25 +436,25 @@ int bake_create(
provider->client->bake_create_id, &handle);
if(hret != HG_SUCCESS) {
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
if(ret == 0)
if(ret == BAKE_SUCCESS)
*rid = out.rid;
margo_free_output(handle, &out);
......@@ -479,20 +479,20 @@ int bake_persist(
provider->client->bake_persist_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -525,7 +525,7 @@ int bake_create_write_persist(
hret = margo_bulk_create(provider->client->mid, 1, (void**)(&buf), &buf_size,
HG_BULK_READ_ONLY, &in.bulk_handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_create(provider->client->mid, provider->addr,
provider->client->bake_create_write_persist_id, &handle);
......@@ -533,7 +533,7 @@ int bake_create_write_persist(
if(hret != HG_SUCCESS)
{
margo_bulk_free(in.bulk_handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_provider_forward(provider->provider_id, handle, &in);
......@@ -541,7 +541,7 @@ int bake_create_write_persist(
{
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
......@@ -549,7 +549,7 @@ int bake_create_write_persist(
{
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -587,24 +587,24 @@ int bake_create_write_persist_proxy(
provider->client->bake_create_write_persist_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
if(ret == 0)
if(ret == BAKE_SUCCESS)
*rid = out.rid;
margo_free_output(handle, &out);
......@@ -629,20 +629,20 @@ int bake_get_size(
provider->client->bake_get_size_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -674,15 +674,15 @@ int bake_get_data(
if(HG_SUCCESS != margo_addr_to_string(provider->client->mid, self_addr_str, &addr_size, self_addr)) {
margo_addr_free(provider->client->mid, self_addr);
return -1;
return BAKE_ERR_MERCURY;
}
if(HG_SUCCESS != margo_addr_to_string(provider->client->mid, trgt_addr_str, &addr_size, trgt_addr)) {
margo_addr_free(provider->client->mid, self_addr);
return -1;
return BAKE_ERR_MERCURY;
}
if(strcmp(self_addr_str, trgt_addr_str) != 0) {
margo_addr_free(provider->client->mid, self_addr);
return -1;
return BAKE_ERR_MERCURY;
}
margo_addr_free(provider->client->mid, self_addr);
......@@ -692,20 +692,20 @@ int bake_get_data(
provider->client->bake_get_data_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -725,17 +725,17 @@ int bake_noop(bake_provider_handle_t provider)
provider->client->bake_noop_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, NULL);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
margo_destroy(handle);
return(0);
return BAKE_SUCCESS;
}
static int bake_eager_read(
......@@ -760,20 +760,20 @@ static int bake_eager_read(
provider->client->bake_eager_read_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -812,7 +812,7 @@ int bake_read(
hret = margo_bulk_create(provider->client->mid, 1, (void**)(&buf), &buf_size,
HG_BULK_WRITE_ONLY, &in.bulk_handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_create(provider->client->mid, provider->addr,
provider->client->bake_read_id, &handle);
......@@ -820,7 +820,7 @@ int bake_read(
if(hret != HG_SUCCESS)
{
margo_bulk_free(in.bulk_handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_provider_forward(provider->provider_id, handle, &in);
......@@ -828,7 +828,7 @@ int bake_read(
{
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
......@@ -836,7 +836,7 @@ int bake_read(
{
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -875,20 +875,20 @@ int bake_proxy_read(
provider->client->bake_read_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......@@ -915,20 +915,20 @@ int bake_remove(
provider->client->bake_remove_id, &handle);
if(hret != HG_SUCCESS)
return(-1);
return BAKE_ERR_MERCURY;
hret = margo_provider_forward(provider->provider_id, handle, &in);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS)
{
margo_destroy(handle);
return(-1);
return BAKE_ERR_MERCURY;
}
ret = out.ret;
......
......@@ -54,7 +54,7 @@ int bake_makepool(
if(!pool)
{
fprintf(stderr, "pmemobj_create: %s\n", pmemobj_errormsg());
return(-1);
return BAKE_ERR_PMEM;
}
/* find root */
......@@ -64,15 +64,10 @@ int bake_makepool(
/* store the target id for this bake pool at the root */
uuid_generate(root->pool_id.id);
pmemobj_persist(pool, root, sizeof(bake_root_t));
#if 0
char target_string[64];
uuid_unparse(root->id, target_string);
fprintf(stderr, "created BAKE target ID: %s\n", target_string);
#endif
pmemobj_close(pool);
return(0);
return BAKE_SUCCESS;
}
int bake_provider_register(
......@@ -90,14 +85,14 @@ int bake_provider_register(
margo_provider_registered_name(mid, "bake_probe_rpc", provider_id, &id, &flag);
if(flag == HG_TRUE) {
fprintf(stderr, "bake_provider_register(): a provider with the same id (%d) already exists\n", provider_id);
return -1;
return BAKE_ERR_MERCURY;
}
}
/* allocate the resulting structure */
tmp_svr_ctx = calloc(1,sizeof(*tmp_svr_ctx));
if(!tmp_svr_ctx)
return(-1);
return BAKE_ERR_ALLOCATION;
/* register RPCs */
hg_id_t rpc_id;
......@@ -155,7 +150,7 @@ int bake_provider_register(
if(provider != BAKE_PROVIDER_IGNORE)
*provider = tmp_svr_ctx;
return(0);
return BAKE_SUCCESS;
}
int bake_provider_add_storage_target(
......@@ -169,7 +164,7 @@ int bake_provider_add_storage_target(
if(!(new_entry->pmem_pool)) {
fprintf(stderr, "pmemobj_open: %s\n", pmemobj_errormsg());
free(new_entry);
return -1;
return BAKE_ERR_PMEM;
}
/* check to make sure the root is properly set */
......@@ -183,7 +178,7 @@ int bake_provider_add_storage_target(
fprintf(stderr, "Error: BAKE pool %s is not properly initialized\n", target_name);
pmemobj_close(new_entry->pmem_pool);
free(new_entry);
return(-1);
return BAKE_ERR_UNKNOWN_TARGET;
}
/* insert in the provider's hash */
......@@ -195,12 +190,12 @@ int bake_provider_add_storage_target(
fprintf(stderr, "Error: BAKE could not insert new pmem pool into the hash\n");
pmemobj_close(new_entry->pmem_pool);
free(new_entry);
return -1;
return BAKE_ERR_ALLOCATION;
}
provider->num_targets += 1;
*target_id = key;
return 0;
return BAKE_SUCCESS;
}
static bake_pmem_entry_t* find_pmem_entry(
......@@ -218,7 +213,7 @@ int bake_provider_remove_storage_target(
{
bake_pmem_entry_t* entry = NULL;
HASH_FIND(hh, provider->targets, &target_id, sizeof(bake_target_id_t), entry);
if(!entry) return -1;
if(!entry) return BAKE_ERR_UNKNOWN_TARGET;
pmemobj_close(entry->pmem_pool);
HASH_DEL(provider->targets, entry);
free(entry);
......@@ -235,7 +230,7 @@ int bake_provider_remove_all_storage_targets(
free(p);
}
provider->num_targets = 0;
return 0;
return BAKE_SUCCESS;
}
int bake_provider_count_storage_targets(
......@@ -243,7 +238,7 @@ int bake_provider_count_storage_targets(
uint64_t* num_targets)
{
*num_targets = provider->num_targets;
return 0;
return BAKE_SUCCESS;
}
int bake_provider_list_storage_targets(
......@@ -256,7 +251,7 @@ int bake_provider_list_storage_targets(
targets[i] = p->target_id;
i += 1;
}
return 0;
return BAKE_SUCCESS;
}
/* service a remote RPC that creates a BAKE region */
......@@ -273,18 +268,20 @@ static void bake_create_ult(hg_handle_t handle)
bake_provider_t svr_ctx =
margo_registered_data(mid, info->id);
if(!svr_ctx) {
fprintf(stderr, "Error: BAKE create could not find provider\n");
out.ret = BAKE_ERR_UNKNOWN_PROVIDER;
goto respond_with_error;
}
hret = margo_get_input(handle, &in);
if(hret != HG_SUCCESS)
if(hret != HG_SUCCESS) {
out.ret = BAKE_ERR_MERCURY;
goto respond_with_error;
}
/* find the pmem pool */
bake_pmem_entry_t* entry = find_pmem_entry(svr_ctx, in.bti);
if(entry == NULL) {
fprintf(stderr, "Error: BAKE create could not find storage target\n");
out.ret = BAKE_ERR_UNKNOWN_TARGET;
goto respond_with_error;
}
......@@ -295,19 +292,21 @@ static void bake_create_ult(hg_handle_t handle)
prid = (pmemobj_region_id_t*)out.rid.data;
prid->size = in.region_size;
/* find the pmem pool */
out.ret = pmemobj_alloc(entry->pmem_pool, &prid->oid,
int ret = pmemobj_alloc(entry->pmem_pool, &prid->oid,
in.region_size, 0, NULL, NULL);
if(ret != 0)
out.ret = BAKE_ERR_PMEM;
margo_free_input(handle, &in);
margo_respond(handle, &out);
out.ret = BAKE_SUCCESS;
finish:
margo_free_input(handle, &in);
margo_destroy(handle);
return;
respond_with_error:
out.ret = -1;
margo_respond(handle, &out);
goto finish;
}
......@@ -319,9 +318,9 @@ static void bake_write_ult(hg_handle_t handle)
bake_write_out_t out;
bake_write_in_t in;
hg_return_t hret;
hg_addr_t src_addr;
hg_addr_t src_addr = HG_ADDR_NULL;
char* buffer;
hg_bulk_t bulk_handle;
hg_bulk_t bulk_handle = HG_BULK_NULL;
const struct hg_info *hgi;
margo_instance_id mid;
pmemobj_region_id_t* prid;
......@@ -333,7 +332,7 @@ static void bake_write_ult(hg_handle_t handle)
hgi = margo_get_info(handle);
bake_provider_t svr_ctx = margo_registered_data(mid, hgi->id);
if(!svr_ctx) {
out.ret = -1;
out.ret = BAKE_ERR_UNKNOWN_PROVIDER;
margo_respond(handle, &out);
margo_destroy(handle);
return;
......@@ -342,7 +341,7 @@ static void bake_write_ult(hg_handle_t handle)
hret = margo_get_input(handle, &in);
if(hret != HG_SUCCESS)
{
out.ret = -1;
out.ret = BAKE_ERR_MERCURY;
margo_respond(handle, &out);
margo_destroy(handle);
return;
......@@ -354,12 +353,14 @@ static void bake_write_ult(hg_handle_t handle)
buffer = pmemobj_direct(prid->oid);