diff --git a/maestro/pool_manager_registry.c b/maestro/pool_manager_registry.c index f4c811b86b4c87a7847404f7aa6b001281eca35d..b0d3d3b58c4579e8bfad6df628c6e6853d8d97c7 100644 --- a/maestro/pool_manager_registry.c +++ b/maestro/pool_manager_registry.c @@ -182,7 +182,7 @@ mstro_pm_app_register(const struct mstro_endpoint *ep, if(status!=MSTRO_OK) { ERR("Failed to create new regentry\n"); - goto BAILOUT; + return status; } e->ep = (struct mstro_endpoint *) ep; @@ -205,7 +205,6 @@ mstro_pm_app_register(const struct mstro_endpoint *ep, DEBUG("Garbage-collecting previous app entry for %s/%zu (app %" PRIappid ")\n", elt->component_name, elt->component_index); HASH_DEL(g_mstro_pm_app_registry, elt); - goto unlock; } else { ERR("Duplicate component registration: %s:%" PRIu64 \ " has appid %" PRIappid \ @@ -217,41 +216,30 @@ mstro_pm_app_register(const struct mstro_endpoint *ep, } } } + /**Everythin is fine*/ + assert(status == MSTRO_OK); + /** add app to registry*/ + HASH_ADD(hh, g_mstro_pm_app_registry, + appid, sizeof(mstro_app_id), e); unlock: ;}); if(status!=MSTRO_OK) { mstro_pm_app_reg__entry_dispose(e); - goto BAILOUT; } - - /* - Initialization has already been done above: - e->ep = ep; - e->addr = addr; - e->serialized_desc = serialized_desc; - e->transport_methods = (Mstro__Pool__TransportMethods *)transport_methods; - e->component_name = strdup(component_name); - e->component_index = component_index; - */ - - DEBUG("Registered app %" PRIappid " for %s:%" PRIu64 " with transport methods %p\n", - e->appid, e->component_name, e->component_index, e->transport_methods); - - WITH_LOCKED_APP_REGISTRY({ - HASH_ADD(hh, g_mstro_pm_app_registry, - appid, sizeof(mstro_app_id), e); - }); - - /* return data to caller if interesed */ - if(id_p!=NULL) { - *id_p = e->appid; - } - if(entry_p!=NULL) { - *entry_p = e; + else + { + DEBUG("Registered app %" PRIappid " for %s:%" PRIu64 " with transport methods %p\n", + e->appid, e->component_name, e->component_index, e->transport_methods); + /* return data to caller if interesed */ + if(id_p!=NULL) { + *id_p = e->appid; + } + if(entry_p!=NULL) { + *entry_p = e; + } } -BAILOUT: return status; } @@ -259,13 +247,30 @@ mstro_status mstro_pc_app_register_pending(mstro_app_id id) { struct mstro_pm_app_registry_entry *e=NULL; + struct mstro_pm_app_registry_entry *elt=NULL; + mstro_status status = MSTRO_UNIMPL; status = mstro_pm_app_reg__new_entry(&e, id); if(status==MSTRO_OK) { e->pending = true; WITH_LOCKED_APP_REGISTRY({ - HASH_ADD(hh, g_mstro_pm_app_registry, - appid, sizeof(mstro_app_id), e); + /**check there is no other entry before*/ + HASH_FIND(hh, g_mstro_pm_app_registry, &id, sizeof(mstro_app_id), elt); + if((elt!=NULL) && (elt->pending)) { + ERR("There is alreading a pending entry for app %"PRIappid", should not overwrite \n", id); + return MSTRO_FAIL; + } + else if((elt!=NULL) && (!elt->pending)) + { + ERR("App %"PRIappid" already exists in regsitry, should not overwrite \n", id); + return MSTRO_FAIL; + } + else { // elt == NULL + HASH_ADD(hh, g_mstro_pm_app_registry, + appid, sizeof(mstro_app_id), e); + DEBUG("Added a pending entry for app %"PRIappid" to registry \n", id); + status = MSTRO_OK; + } }); } return status; @@ -284,49 +289,44 @@ mstro_pc_app_register(struct mstro_endpoint *ep, if(id==MSTRO_APP_ID_INVALID) return MSTRO_INVARG; - struct mstro_pm_app_registry_entry *e=NULL; - mstro_status status = mstro_pm_app_reg__new_entry(&e, id); - if(status==MSTRO_OK) { - e->ep = ep; - e->addr = addr; - e->serialized_desc = serialized_desc; - e->pending = false; - - e->transport_methods= (Mstro__Pool__TransportMethods *) transport_methods; - - /* FIXME: we should check that there is no previous entry and - * document whether that's an error or a legal way of overriding - * things */ - /* remove pending entries */ - WITH_LOCKED_APP_REGISTRY({ - struct mstro_pm_app_registry_entry *elt=NULL; - struct mstro_pm_app_registry_entry *tmp=NULL; - HASH_ITER(hh, g_mstro_pm_app_registry, elt, tmp) { - if(elt->appid == e->appid) { - if(elt->pending) { - // remove fake pending entry - DEBUG("Remove pending appid %" PRIappid " (index %" PRIu64 ")\n", - elt->appid, elt->component_index); - HASH_DEL(g_mstro_pm_app_registry, elt); - status = mstro_pm_app_reg__entry_dispose(elt); - } - } - } -unlock: - ;}); + struct mstro_pm_app_registry_entry *elt=NULL; + mstro_status status = MSTRO_OK; + /* FIXME: we should check that there is no previous entry and + * document whether that's an error or a legal way of overriding + * things */ + /* remove pending entries */ + WITH_LOCKED_APP_REGISTRY({ + HASH_FIND(hh, g_mstro_pm_app_registry, &id, sizeof(mstro_app_id), elt); + if((elt!=NULL) && (elt->pending)) { + /**fill it and drop the pending flag*/ + elt->addr = addr; + elt->ep = ep; + elt->serialized_desc = serialized_desc; + elt->transport_methods = (Mstro__Pool__TransportMethods *) transport_methods; + elt->pending = false; + status = MSTRO_OK; + } + else if ((elt != NULL) && (!elt->pending)) + { + //FIXME ...maybe just a warning + ERR("Trying to register app %"PRIappid" twice, may overwrite and corrupt registry...Aborting\n", id); + status = MSTRO_FAIL; + } + else /*elt == NULL */ + { + //FIXME ...maybe just a warning + ERR("Trying to add app %"PRIappid" to registry without having a pending entry, should not happen...Aborting\n", id); + status = MSTRO_FAIL; + } - WITH_LOCKED_APP_REGISTRY({ - HASH_ADD(hh, g_mstro_pm_app_registry, - appid, sizeof(mstro_app_id), e); - }); - - /* return data to caller if interesed */ - if(entry_p!=NULL) { - *entry_p = e; - } + ;}); + /* return data to caller if interesed */ + if(entry_p!=NULL) { + *entry_p = elt; } + return status; } @@ -373,8 +373,8 @@ mstro_pm_app_lookup(mstro_app_id appid, struct mstro_pm_app_registry_entry *e=NULL; HASH_FIND(hh, g_mstro_pm_app_registry, &appid, sizeof(mstro_app_id), e); if((e!=NULL) && (e->pending)) { - status = MSTRO_WOULDBLOCK; - *app_entry_p = NULL; + status = MSTRO_WOULDBLOCK; + *app_entry_p = NULL; } else if( (e!=NULL) &&(!e->pending)) {