-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnida_conf.c
38 lines (31 loc) · 831 Bytes
/
nida_conf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "nida_conf.h"
#include <infiniband/verbs.h>
#include <log.h>
#include <rdma_cma.h>
#include <stdlib.h>
#include <unistd.h>
struct ibv_context *nida_get_rdma_dev_context(char *devname)
{
int num_devices;
struct ibv_context **dev_list = rdma_get_devices(&num_devices);
struct ibv_context *rdma_dev = NULL;
if (num_devices < 1) {
log_fatal("No RDMA device found. Exiting..");
_exit(EXIT_FAILURE);
}
if (!devname) {
log_info("Using default RDMA device %s", dev_list[0]->device->name);
return dev_list[0];
}
for (int i = 0; i < num_devices; ++i)
if (!strncmp(dev_list[i]->device->name, devname, strlen(devname))) {
rdma_dev = dev_list[i];
break;
}
if (!rdma_dev) {
log_fatal("Cannot find RDMA device %s", devname);
_exit(EXIT_FAILURE);
}
rdma_free_devices(dev_list);
return rdma_dev;
}