#endif
}
-
-Device::Device(CephContext *cct, ibv_device* d, struct ibv_context *dc)
- : device(d), active_port(nullptr)
+Device::Device(CephContext *cct, ibv_device* ib_dev): device(ib_dev), active_port(nullptr)
{
- if (device == NULL) {
- lderr(cct) << __func__ << " device == NULL" << cpp_strerror(errno) << dendl;
- ceph_abort();
- }
+ ceph_assert(device);
+ ctxt = ibv_open_device(device);
+ ceph_assert(ctxt);
+
name = ibv_get_device_name(device);
- if (cct->_conf->ms_async_rdma_cm) {
- ctxt = dc;
- } else {
- ctxt = ibv_open_device(device);
- }
- if (ctxt == NULL) {
- lderr(cct) << __func__ << " open rdma device failed. " << cpp_strerror(errno) << dendl;
+
+ int r = ibv_query_device(ctxt, &device_attr);
+ if (r) {
+ lderr(cct) << __func__ << " failed to query rdma device. " << cpp_strerror(errno) << dendl;
ceph_abort();
}
+}
+
+Device::Device(CephContext *cct, struct ibv_context *ib_ctx): device(ib_ctx->device),
+ active_port(nullptr)
+{
+ ceph_assert(device);
+ ctxt = ib_ctx;
+ ceph_assert(ctxt);
+
+ name = ibv_get_device_name(device);
+
int r = ibv_query_device(ctxt, &device_attr);
if (r) {
lderr(cct) << __func__ << " failed to query rdma device. " << cpp_strerror(errno) << dendl;
const char* name;
uint8_t port_cnt = 0;
public:
- explicit Device(CephContext *c, ibv_device* d, struct ibv_context *dc);
+ explicit Device(CephContext *c, ibv_device* ib_dev);
+ explicit Device(CephContext *c, ibv_context *ib_ctx);
~Device() {
if (active_port) {
delete active_port;
int num;
Device** devices;
public:
- explicit DeviceList(CephContext *cct): device_list(ibv_get_device_list(&num)),
- device_context_list(rdma_get_devices(&num)) {
- if (device_list == NULL || num == 0) {
- lderr(cct) << __func__ << " failed to get rdma device list. " << cpp_strerror(errno) << dendl;
- ceph_abort();
+ explicit DeviceList(CephContext *cct): device_list(nullptr), device_context_list(nullptr),
+ num(0), devices(nullptr) {
+ device_list = ibv_get_device_list(&num);
+ ceph_assert(device_list);
+ ceph_assert(num);
+ if (cct->_conf->ms_async_rdma_cm) {
+ device_context_list = rdma_get_devices(NULL);
+ ceph_assert(device_context_list);
}
devices = new Device*[num];
for (int i = 0;i < num; ++i) {
- devices[i] = new Device(cct, device_list[i], device_context_list[i]);
+ if (cct->_conf->ms_async_rdma_cm) {
+ devices[i] = new Device(cct, device_context_list[i]);
+ } else {
+ devices[i] = new Device(cct, device_list[i]);
+ }
}
}
~DeviceList() {