diff --git a/src/core/agent_data.h b/src/core/agent_data.h index ec7e1e1de4..a0cc263329 100644 --- a/src/core/agent_data.h +++ b/src/core/agent_data.h @@ -100,6 +100,12 @@ class nixlAgentData { void enqueueCommWork(nixl_comm_req_t request); void getCommWork(std::vector &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: diff --git a/src/core/nixl_agent.cpp b/src/core/nixl_agent.cpp index 74c8d9e7c1..1acfd00a64 100644 --- a/src/core/nixl_agent.cpp +++ b/src/core/nixl_agent.cpp @@ -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; } @@ -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; } } @@ -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; } diff --git a/src/core/nixl_listener.cpp b/src/core/nixl_listener.cpp index 51d7c728b4..2886b78b92 100644 --- a/src/core/nixl_listener.cpp +++ b/src/core/nixl_listener.cpp @@ -663,6 +663,58 @@ void nixlAgentData::getCommWork(std::vector &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) {