]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async/rdma: use ibv_port_attr object type in Port class
authorChangcheng Liu <changcheng.liu@aliyun.com>
Mon, 3 Jun 2019 05:00:22 +0000 (13:00 +0800)
committerChangcheng Liu <changcheng.liu@aliyun.com>
Fri, 23 Aug 2019 02:45:05 +0000 (10:45 +0800)
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 <changcheng.liu@aliyun.com>
src/msg/async/rdma/Infiniband.cc
src/msg/async/rdma/Infiniband.h

index 846f8ad45a0fc98d9b4db59065bd726073e47488..14f05134d1a0930a6a2845ad1a9053a9ad71f1f5 100644 (file)
@@ -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;
index a2d1f4e7c0ae143c9153464d49f692214fc5f530..aaa972bd5989c2cb3f41c7608747a28e7bf42440 100644 (file)
@@ -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; }
 };