Commit c8d4cdb7 authored by Matthieu Dorier's avatar Matthieu Dorier

added the possibility to check if a provider is already registered with a particular provider_id

parent 0948ea23
......@@ -54,6 +54,29 @@ int remi_provider_register(
ABT_pool pool,
remi_provider_t* provider);
/**
* @brief Checks if a REMI provider with the given provider id
* is registered. If yes, flag will be set to 1, provider
* will be set to the registered provider, and pool will be set
* to its associated pool. If not, flag will be
* set to 0, pool will be set to ABT_POOL_NULL, and the provider
* parameter will be set to REMI_PROVIDER_NULL.
*
* @param[in] mid Margo instance.
* @param[in] provider_id Provider id.
* @param[out] flag 1 if provider is registered, 0 otherwise.
* @param[out] pool Pool used to register the provider.
* @param[out] provider Registered provider (if it exists).
*
* @return REMI_SUCCESS or error code defined in remi-common.h.
*/
int remi_provider_registered(
margo_instance_id mid,
uint16_t provider_id,
int* flag,
ABT_pool* pool,
remi_provider_t* provider);
/**
* @brief Registers a migration class by providing a callback
* to call when a fileset of that class is migrated.
......
......@@ -13,6 +13,7 @@
#include <sys/mman.h>
#include <string.h>
#include <iostream>
#include <unordered_map>
#include <thallium.hpp>
#include "remi/remi-server.h"
#include "remi-fileset.hpp"
......@@ -28,8 +29,10 @@ struct migration_class {
struct remi_provider : public tl::provider<remi_provider> {
std::unordered_map<std::string, migration_class> m_migration_classes;
tl::engine* m_engine;
std::unordered_map<std::string, migration_class> m_migration_classes;
tl::engine* m_engine;
tl::pool& m_pool;
static std::unordered_map<uint16_t, remi_provider*> m_registered_providers;
void migrate(
const tl::request& req,
......@@ -141,12 +144,19 @@ struct remi_provider : public tl::provider<remi_provider> {
}
remi_provider(tl::engine* e, uint16_t provider_id, tl::pool& pool)
: tl::provider<remi_provider>(*e, provider_id), m_engine(e) {
define("remi_migrate", &remi_provider::migrate);
}
: tl::provider<remi_provider>(*e, provider_id), m_engine(e), m_pool(pool) {
define("remi_migrate", &remi_provider::migrate, pool);
m_registered_providers[provider_id] = this;
}
~remi_provider() {
m_registered_providers.erase(get_provider_id());
}
};
std::unordered_map<uint16_t, remi_provider*> remi_provider::m_registered_providers;
static void on_finalize(void* uargs) {
auto provider = static_cast<remi_provider_t>(uargs);
for(auto& klass : provider->m_migration_classes) {
......@@ -172,6 +182,27 @@ extern "C" int remi_provider_register(
return REMI_SUCCESS;
}
extern "C" int remi_provider_registered(
margo_instance_id mid,
uint16_t provider_id,
int* flag,
ABT_pool* pool,
remi_provider_t* provider)
{
auto it = remi_provider::m_registered_providers.find(provider_id);
if(it == remi_provider::m_registered_providers.end()) {
*pool = ABT_POOL_NULL;
*provider = REMI_PROVIDER_NULL;
*flag = 0;
} else {
remi_provider* p = it->second;
if(provider) *provider = p;
if(pool) *pool = p->m_pool.native_handle();
*flag = 1;
}
return REMI_SUCCESS;
}
extern "C" int remi_provider_register_migration_class(
remi_provider_t provider,
const char* class_name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment