Skip to content

Commit

Permalink
ibdiags: Use cl_qmap instead of glib hashtable
Browse files Browse the repository at this point in the history
These do basically the same thing for this purpose, no reason to have a
glib dependency for such a simple data structure.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
  • Loading branch information
jgunthorpe committed May 7, 2019
1 parent b8c6a14 commit 1616816
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
3 changes: 1 addition & 2 deletions README
Expand Up @@ -13,8 +13,7 @@ Dependencies:
1) libibumad >= 1.3.7
2) opensm-libs >= 3.3.10
3) ib_umad kernel module
4) glib2


Python dependencies:
1) docutils

Expand Down
9 changes: 0 additions & 9 deletions configure.ac
Expand Up @@ -155,15 +155,6 @@ IBSCRIPTPATH_TMP2="`echo $IBSCRIPTPATH_TMP1 | sed 's/^NONE/$ac_default_prefix/'`
IBSCRIPTPATH="${with_ibpath_override:-`eval echo $IBSCRIPTPATH_TMP2`}"
AC_SUBST(IBSCRIPTPATH)

dnl check for glib
PKG_CHECK_MODULES([GLIB], [glib-2.0], ac_glib=yes, ac_glib=no)
AM_CONDITIONAL([HAVE_GLIB], test "$ac_glib" = "yes")
if test "$ac_glib" = "yes"; then
AC_DEFINE([HAVE_GLIB], 1, [Define to 1 to indicate GLIB support])
else
AC_MSG_ERROR(glib not found; glib2 is required)
fi

dnl Begin libibnetdisc stuff
ibnetdisc_api_version=`grep LIBVERSION $srcdir/libibnetdisc/libibnetdisc.ver | sed 's/LIBVERSION=//'`
if test -z $ibnetdisc_api_version; then
Expand Down
4 changes: 2 additions & 2 deletions infiniband-diags.spec.in
Expand Up @@ -11,8 +11,8 @@ Group: System Environment/Libraries
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Source: https://github.com/linux-rdma/%{name}/releases/download/%{version}/%{name}-%{version}.tar.gz
Url: https://github.com/linux-rdma/%{name}/
BuildRequires: opensm-devel, libibumad-devel, glib2-devel
Requires: opensm-libs, libibumad, glib2
BuildRequires: opensm-devel, libibumad-devel
Requires: opensm-libs, libibumad
Provides: perl(IBswcountlimits)
Obsoletes: openib-diags
Provides: libibmad = %{version}-%{release}
Expand Down
4 changes: 2 additions & 2 deletions libibnetdisc/Makefile.am
Expand Up @@ -25,10 +25,10 @@ endif

libibnetdisc_la_SOURCES = src/ibnetdisc.c src/ibnetdisc_cache.c src/chassis.c \
src/chassis.h src/internal.h src/query_smp.c
libibnetdisc_la_CFLAGS = -Wall $(DBGFLAGS) $(GLIB_CFLAGS)
libibnetdisc_la_CFLAGS = -Wall $(DBGFLAGS)
libibnetdisc_la_LDFLAGS = -version-info $(ibnetdisc_api_version) \
-export-dynamic $(libibnetdisc_version_script) \
-L$(top_builddir)/libibmad -libmad $(GLIB_LIBS)
-L$(top_builddir)/libibmad -libmad
libibnetdisc_la_DEPENDENCIES = $(srcdir)/src/libibnetdisc.map

libibnetdiscincludedir = $(includedir)/infiniband
Expand Down
40 changes: 28 additions & 12 deletions libibnetdisc/src/ibnetdisc.c
Expand Up @@ -55,6 +55,9 @@
#include "internal.h"
#include "chassis.h"

#define container_of(ptr, type, member) \
((type *)((uint8_t *)(ptr)-offsetof(type, member)))

/* forward declarations */
struct ni_cbdata
{
Expand Down Expand Up @@ -380,7 +383,7 @@ static int recv_port_info(smp_engine_t * engine, ibnd_smp_t * smp,
" to insert new port guid 0x%016" PRIx64 " to DB\n",
port->guid);

add_to_portlid_hash(port, f_int->lid2guid);
add_to_portlid_hash(port, f_int);

if ((scan->cfg->flags & IBND_CONFIG_MLX_EPI)
&& is_mlnx_ext_port_info_supported(port)) {
Expand Down Expand Up @@ -675,20 +678,28 @@ int add_to_portguid_hash(ibnd_port_t * port, ibnd_port_t * hash[])
return rc;
}

struct lid2guid_item {
cl_map_item_t cl_map;
ibnd_port_t *port;
};

void create_lid2guid(f_internal_t *f_int)
{
f_int->lid2guid = g_hash_table_new_full(g_direct_hash, g_direct_equal,
NULL, NULL);
cl_qmap_init(&f_int->lid2guid);
}

void destroy_lid2guid(f_internal_t *f_int)
{
if (f_int->lid2guid) {
g_hash_table_destroy(f_int->lid2guid);
cl_map_item_t *item;

for (item = cl_qmap_head(&f_int->lid2guid); item != cl_qmap_end(&f_int->lid2guid);
item = cl_qmap_head(&f_int->lid2guid)) {
cl_qmap_remove_item(&f_int->lid2guid, item);
free(container_of(item, struct lid2guid_item, cl_map));
}
}

void add_to_portlid_hash(ibnd_port_t * port, GHashTable *htable)
void add_to_portlid_hash(ibnd_port_t * port, f_internal_t *f_int)
{
uint16_t base_lid = port->base_lid;
uint16_t lid_mask = ((1 << port->lmc) -1);
Expand All @@ -698,7 +709,14 @@ void add_to_portlid_hash(ibnd_port_t * port, GHashTable *htable)
/* We add the port for all lids
* so it is easier to find any "random" lid specified */
for (lid = base_lid; lid <= (base_lid + lid_mask); lid++) {
g_hash_table_insert(htable, GINT_TO_POINTER(lid), port);
struct lid2guid_item *item;

item = malloc(sizeof(*item));
if (item) {
item->port = port;
cl_qmap_insert(&f_int->lid2guid, lid,
&item->cl_map);
}
}
}
}
Expand Down Expand Up @@ -918,13 +936,11 @@ void ibnd_iter_nodes_type(ibnd_fabric_t * fabric, ibnd_iter_node_func_t func,
ibnd_port_t *ibnd_find_port_lid(ibnd_fabric_t * fabric,
uint16_t lid)
{
ibnd_port_t *port;
f_internal_t *f = (f_internal_t *)fabric;

port = (ibnd_port_t *)g_hash_table_lookup(f->lid2guid,
GINT_TO_POINTER(lid));

return port;
return container_of(cl_qmap_get(&f->lid2guid, lid),
struct lid2guid_item, cl_map)
->port;
}

ibnd_port_t *ibnd_find_port_guid(ibnd_fabric_t * fabric, uint64_t guid)
Expand Down
2 changes: 1 addition & 1 deletion libibnetdisc/src/ibnetdisc_cache.c
Expand Up @@ -614,7 +614,7 @@ static int _rebuild_ports(ibnd_fabric_cache_t * fabric_cache)
} else
port->remoteport = NULL;

add_to_portlid_hash(port, fabric_cache->f_int->lid2guid);
add_to_portlid_hash(port, fabric_cache->f_int);
port_cache = port_cache_next;
}

Expand Down
5 changes: 2 additions & 3 deletions libibnetdisc/src/internal.h
Expand Up @@ -40,7 +40,6 @@

#include <infiniband/ibnetdisc.h>
#include <complib/cl_qmap.h>
#include <glib.h>

#define IBND_DEBUG(fmt, ...) \
if (ibdebug) { \
Expand All @@ -60,12 +59,12 @@

typedef struct f_internal {
ibnd_fabric_t fabric;
GHashTable *lid2guid;
cl_qmap_t lid2guid;
} f_internal_t;
f_internal_t *allocate_fabric_internal(void);
void create_lid2guid(f_internal_t *f_int);
void destroy_lid2guid(f_internal_t *f_int);
void add_to_portlid_hash(ibnd_port_t * port, GHashTable *htable);
void add_to_portlid_hash(ibnd_port_t * port, f_internal_t *f_int);

typedef struct ibnd_scan {
ib_portid_t selfportid;
Expand Down

0 comments on commit 1616816

Please sign in to comment.