sunce4t commented on issue #3119:
URL: https://github.com/apache/brpc/issues/3119#issuecomment-3441174595
static int IsOthersGid(const std::string& device_name, int port_num, int
gid_index) {
std::string path = "/sys/class/infiniband/" + device_name +
"/ports/" + std::to_string(port_num) +
"/gids/" + std::to_string(gid_index);
#ifdef __linux__
std::ifstream file(path);
if (!file.is_open()) {
return -1;
}
std::string line;
if (!std::getline(file, line)) {
return -2;
}
if (line == "0000:0000:0000:0000:0000:0000:0000:0000" ||
line == "fe80:0000:0000:0000:0000:0000:0000:0000" ) {
return 1;
}
return 0;
#else
LOG(INFO) << "Fix of FindRdmaGid currently only supports linux";
return 0;
#endif
}
static bool FindRdmaGid(ibv_context* context) {
bool found = false;
const char* device_name_cstr = IbvGetDeviceName(context->device);
std::string device_name(device_name_cstr);
for (int i = g_gid_tbl_len - 1; i >= 0; --i) {
ibv_gid gid;
if (IbvQueryGid(context, g_port_num, i, &gid) != 0) {
continue;
}
if (gid.global.interface_id == 0) {
continue;
}
if (FLAGS_rdma_gid_index == i) {
g_gid = gid;
g_gid_index = i;
return true;
}
if(IsOthersGid(device_name, g_port_num, i) != 0) {
continue;
}
// For infiniband, there is only one GID for each port.
// For RoCE, there are 2 GIDs for each MAC and 2 GIDs for each IP.
// Generally, the last GID is a RoCEv2-type GID generated by IP.
if (!found) {
g_gid = gid;
g_gid_index = i;
found = true;
}
}
if (FLAGS_rdma_gid_index >= 0 && g_gid_index != FLAGS_rdma_gid_index) {
found = false;
}
return found;
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]