From 4810e40d440123966da50aceeffcd4005117e4ff Mon Sep 17 00:00:00 2001 From: Changcheng Liu Date: Mon, 3 Jun 2019 13:00:22 +0800 Subject: [PATCH] msg/async/rdma: use ibv_port_attr object type in Port class 1. Avoid to do memory management without using pointer to operate operate the allocated space. Or, it could have memory leak. 2. Since member type has been changed in class Device, it need to use member domain operator "." to access to the sub-member in object. 3. There's no need to consider experimental API of ibv_query_port. So, merge ibv_query_port in the prolog. Signed-off-by: Changcheng Liu --- src/msg/async/rdma/Infiniband.cc | 27 +++++++++++---------------- src/msg/async/rdma/Infiniband.h | 4 ++-- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/msg/async/rdma/Infiniband.cc b/src/msg/async/rdma/Infiniband.cc index 846f8ad45a0..14f05134d1a 100644 --- a/src/msg/async/rdma/Infiniband.cc +++ b/src/msg/async/rdma/Infiniband.cc @@ -30,21 +30,23 @@ static const uint32_t MAX_INLINE_DATA = 0; static const uint32_t TCP_MSG_LEN = sizeof("0000:00000000:00000000:00000000:00000000000000000000000000000000"); static const uint32_t CQ_DEPTH = 30000; -Port::Port(CephContext *cct, struct ibv_context* ictxt, uint8_t ipn): ctxt(ictxt), port_num(ipn), port_attr(new ibv_port_attr), gid_idx(0) +Port::Port(CephContext *cct, struct ibv_context* ictxt, uint8_t ipn): ctxt(ictxt), port_num(ipn), gid_idx(0) { + int r = ibv_query_port(ctxt, port_num, &port_attr); + if (r == -1) { + lderr(cct) << __func__ << " query port failed " << cpp_strerror(errno) << dendl; + ceph_abort(); + } + + lid = port_attr.lid; + #ifdef HAVE_IBV_EXP union ibv_gid cgid; struct ibv_exp_gid_attr gid_attr; bool malformed = false; ldout(cct,1) << __func__ << " using experimental verbs for gid" << dendl; - int r = ibv_query_port(ctxt, port_num, port_attr); - if (r == -1) { - lderr(cct) << __func__ << " query port failed " << cpp_strerror(errno) << dendl; - ceph_abort(); - } - lid = port_attr->lid; // search for requested GID in GIDs table ldout(cct, 1) << __func__ << " looking for local GID " << (cct->_conf->ms_async_rdma_local_gid) @@ -68,7 +70,7 @@ Port::Port(CephContext *cct, struct ibv_context* ictxt, uint8_t ipn): ctxt(ictxt gid_attr.comp_mask = IBV_EXP_QUERY_GID_ATTR_TYPE; - for (gid_idx = 0; gid_idx < port_attr->gid_tbl_len; gid_idx++) { + for (gid_idx = 0; gid_idx < port_attr.gid_tbl_len; gid_idx++) { r = ibv_query_gid(ctxt, port_num, gid_idx, &gid); if (r) { lderr(cct) << __func__ << " query gid of port " << port_num << " index " << gid_idx << " failed " << cpp_strerror(errno) << dendl; @@ -88,18 +90,11 @@ Port::Port(CephContext *cct, struct ibv_context* ictxt, uint8_t ipn): ctxt(ictxt } } - if (gid_idx == port_attr->gid_tbl_len) { + if (gid_idx == port_attr.gid_tbl_len) { lderr(cct) << __func__ << " Requested local GID was not found in GID table" << dendl; ceph_abort(); } #else - int r = ibv_query_port(ctxt, port_num, port_attr); - if (r == -1) { - lderr(cct) << __func__ << " query port failed " << cpp_strerror(errno) << dendl; - ceph_abort(); - } - - lid = port_attr->lid; r = ibv_query_gid(ctxt, port_num, 0, &gid); if (r) { lderr(cct) << __func__ << " query gid failed " << cpp_strerror(errno) << dendl; diff --git a/src/msg/async/rdma/Infiniband.h b/src/msg/async/rdma/Infiniband.h index a2d1f4e7c0a..aaa972bd598 100644 --- a/src/msg/async/rdma/Infiniband.h +++ b/src/msg/async/rdma/Infiniband.h @@ -58,7 +58,7 @@ class CephContext; class Port { struct ibv_context* ctxt; int port_num; - struct ibv_port_attr* port_attr; + struct ibv_port_attr port_attr; uint16_t lid; int gid_idx = 0; union ibv_gid gid; @@ -68,7 +68,7 @@ class Port { uint16_t get_lid() { return lid; } ibv_gid get_gid() { return gid; } int get_port_num() { return port_num; } - ibv_port_attr* get_port_attr() { return port_attr; } + ibv_port_attr* get_port_attr() { return &port_attr; } int get_gid_idx() { return gid_idx; } }; -- 2.39.5