Skip to content
Merged
6 changes: 6 additions & 0 deletions src/core/agent_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class nixlAgentData {
void enqueueCommWork(nixl_comm_req_t request);
void getCommWork(std::vector<nixl_comm_req_t> &req_list);
nixl_status_t
loadConnInfo(const std::string &remote_name,
const nixl_backend_t &backend,
const nixl_blob_t &conn_info);
nixl_status_t
loadRemoteSections(const std::string &remote_name, nixlSerDes &sd);
nixl_status_t
invalidateRemoteData(const std::string &remote_name);

public:
Expand Down
44 changes: 7 additions & 37 deletions src/core/nixl_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ nixlAgent::loadRemoteMD (const nixl_blob_t &remote_metadata,

size_t conn_cnt;
ret = sd.getBuf("Conns", &conn_cnt, sizeof(conn_cnt));
if(ret) {
if (ret != NIXL_SUCCESS) {
NIXL_ERROR << "Error getting connection count: " << nixlEnumStrings::statusStr(ret);
return ret;
}
Expand All @@ -1351,32 +1351,11 @@ nixlAgent::loadRemoteMD (const nixl_blob_t &remote_metadata,
return NIXL_ERR_MISMATCH;
}

// Current agent might not support a remote backend
if (data->backendEngines.count(nixl_backend) != 0) {

// No need to reload same conn info, error if it changed
if (data->remoteBackends.count(remote_agent) != 0 &&
data->remoteBackends[remote_agent].count(nixl_backend) != 0) {
if (data->remoteBackends[remote_agent][nixl_backend] != conn_info)
return NIXL_ERR_NOT_ALLOWED;
count++;
continue;
}

nixlBackendEngine *eng = data->backendEngines[nixl_backend];
if (eng->supportsRemote()) {
ret = eng->loadRemoteConnInfo(remote_agent, conn_info);
if (ret != NIXL_SUCCESS) {
return ret; // Error in load
}

count++;
data->remoteBackends[remote_agent].emplace(nixl_backend, conn_info);
} else {
// If there was an issue and we return error while some connections
// are loaded, they will be deleted in the backend destructor.
return NIXL_ERR_UNKNOWN; // This is an erroneous case
}
ret = data->loadConnInfo(remote_agent, nixl_backend, conn_info);
if (ret == NIXL_SUCCESS) {
count++;
} else if (ret != NIXL_ERR_NOT_SUPPORTED) {
return ret;
}
}

Expand All @@ -1389,17 +1368,8 @@ nixlAgent::loadRemoteMD (const nixl_blob_t &remote_metadata,
return NIXL_ERR_MISMATCH;
}

if (data->remoteSections.count(remote_agent) == 0) {
data->remoteSections[remote_agent] = new nixlRemoteSection(remote_agent);
}

ret = data->remoteSections[remote_agent]->loadRemoteData(&sd, data->backendEngines);

// TODO: can be more graceful, if just the new MD blob was improper
ret = data->loadRemoteSections(remote_agent, sd);
if (ret != NIXL_SUCCESS) {
delete data->remoteSections[remote_agent];
data->remoteSections.erase(remote_agent);
data->remoteBackends.erase(remote_agent);
return ret;
}

Expand Down
52 changes: 52 additions & 0 deletions src/core/nixl_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,58 @@ void nixlAgentData::getCommWork(std::vector<nixl_comm_req_t> &req_list){
commQueue.clear();
}

nixl_status_t
nixlAgentData::loadConnInfo(const std::string &remote_name,
const nixl_backend_t &backend,
const nixl_blob_t &conn_info) {
if (backendEngines.count(backend) == 0) {
NIXL_DEBUG << "Agent " << name << " does not support a remote backend: " << backend;
return NIXL_ERR_NOT_SUPPORTED;
}

// No need to reload same conn info, error if it changed
if ((remoteBackends.count(remote_name) != 0) &&
(remoteBackends[remote_name].count(backend) != 0)) {
if (remoteBackends[remote_name][backend] != conn_info) {
return NIXL_ERR_NOT_ALLOWED;
}

return NIXL_SUCCESS;
}

nixlBackendEngine *eng = backendEngines[backend];
if (!eng->supportsRemote()) {
NIXL_DEBUG << backend << " does not support remote operations";
return NIXL_ERR_NOT_SUPPORTED;
}

const nixl_status_t ret = eng->loadRemoteConnInfo(remote_name, conn_info);
if (ret != NIXL_SUCCESS) {
return ret;
}

remoteBackends[remote_name].emplace(backend, conn_info);
return NIXL_SUCCESS;
}

nixl_status_t
nixlAgentData::loadRemoteSections(const std::string &remote_name, nixlSerDes &sd) {
if (remoteSections.count(remote_name) == 0) {
remoteSections[remote_name] = new nixlRemoteSection(remote_name);
}

const nixl_status_t ret = remoteSections[remote_name]->loadRemoteData(&sd, backendEngines);
// TODO: can be more graceful, if just the new MD blob was improper
if (ret != NIXL_SUCCESS) {
delete remoteSections[remote_name];
remoteSections.erase(remote_name);
remoteBackends.erase(remote_name);
return ret;
}

return NIXL_SUCCESS;
}

nixl_status_t
nixlAgentData::invalidateRemoteData(const std::string &remote_name) {
if (remote_name == name) {
Expand Down