Skip to content

Commit

Permalink
Merge pull request #26 from jgunthorpe/sparse_bugs
Browse files Browse the repository at this point in the history
Sparse bugs
  • Loading branch information
weiny2 committed May 8, 2019
2 parents b8c6a14 + 267969c commit 45a0523
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 60 deletions.
3 changes: 1 addition & 2 deletions README
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
3 changes: 1 addition & 2 deletions src/ibqueryerrors.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,9 @@ static int query_cap_mask(ib_portid_t * portid, char *node_name, int portnum,
/* ClassPortInfo should be supported as part of libibmad */
memcpy(&rc_cap_mask, pc + 2, sizeof(rc_cap_mask)); /* CapabilityMask */
memcpy(&rc_cap_mask2, pc + 4, sizeof(rc_cap_mask2)); /* CapabilityMask2 */
rc_cap_mask2 = ntohl(rc_cap_mask2) >> 5;

*cap_mask = rc_cap_mask;
*cap_mask2 = rc_cap_mask2;
*cap_mask2 = ntohl(rc_cap_mask2) >> 5;
return 0;
}

Expand Down
7 changes: 3 additions & 4 deletions src/mcm_rereg_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static uint64_t build_mcm_rec(uint8_t *data, ibmad_gid_t mgid,
mad_set_array(data, 0, IB_SA_MCM_PORTGID_F, port_gid);
mad_set_field(data, 0, IB_SA_MCM_JOIN_STATE_F, 1);

return IB_MCR_COMPMASK_MGID | IB_MCR_COMPMASK_PORT_GID |
IB_MCR_COMPMASK_JOIN_STATE;
return be64toh(IB_MCR_COMPMASK_MGID | IB_MCR_COMPMASK_PORT_GID |
IB_MCR_COMPMASK_JOIN_STATE);
}

static void build_mcm_rec_umad(void *umad, ib_portid_t * dport, int method,
Expand Down Expand Up @@ -338,8 +338,7 @@ static int rereg_and_test_port(const char *guid_file, int port, int agent,
}

while (fgets(line, sizeof(line), f)) {
guid = strtoull(line, NULL, 0);
guid = htobe64(guid);
guid = htobe64(strtoull(line, NULL, 0));
memcpy(&port_gid[0], &prefix, 8);
memcpy(&port_gid[8], &guid, 8);

Expand Down
5 changes: 3 additions & 2 deletions src/perfquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ int main(int argc, char **argv)
ib_portid_t portid = { 0 };
int mask = 0xffff;
uint64_t ext_mask = 0xffffffffffffffffULL;
__be32 cap_mask2_be;
uint32_t cap_mask2;
__be16 cap_mask;
int all_ports_loop = 0;
Expand Down Expand Up @@ -920,8 +921,8 @@ int main(int argc, char **argv)
IBEXIT("classportinfo query");
/* ClassPortInfo should be supported as part of libibmad */
memcpy(&cap_mask, pc + 2, sizeof(cap_mask)); /* CapabilityMask */
memcpy(&cap_mask2, pc + 4, sizeof(cap_mask2)); /* CapabilityMask2 */
cap_mask2 = ntohl(cap_mask2) >> 5;
memcpy(&cap_mask2_be, pc + 4, sizeof(cap_mask2_be)); /* CapabilityMask2 */
cap_mask2 = ntohl(cap_mask2_be) >> 5;

if (!(cap_mask & IB_PM_ALL_PORT_SELECT)) { /* bit 8 is AllPortSelect */
if (!info.all_ports && info.port == ALL_PORTS)
Expand Down
7 changes: 3 additions & 4 deletions src/saquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void print_node_desc(ib_node_record_t * node_record)

if (p_ni->node_type == IB_NODE_TYPE_CA) {
name = remap_node_name(node_name_map,
node_record->node_info.node_guid,
be64toh(node_record->node_info.node_guid),
(char *)p_nd->description);
printf("%6d \"%s\"\n", be16toh(node_record->lid), name);
free(name);
Expand Down Expand Up @@ -376,7 +376,7 @@ static void dump_multicast_member_record(ib_member_rec_t *p_mcmr,
if(node_name != NULL)
free(node_name);
node_name = remap_node_name(node_name_map,
nr->node_info.node_guid,
be64toh(nr->node_info.node_guid),
(char *)nr->node_desc.description);
break;
}
Expand Down Expand Up @@ -1901,8 +1901,7 @@ int main(int argc, char **argv)
default:
if ((!q && !(q = find_query_by_type(query_type)))
|| !q->handler) {
fprintf(stderr, "Unknown query type %d\n",
ntohs(query_type));
fprintf(stderr, "Unknown query type %d\n", query_type);
status = EINVAL;
} else
status = q->handler(q, h, &params, argc, argv);
Expand Down
31 changes: 14 additions & 17 deletions src/vendstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ typedef struct {
typedef struct {
uint8_t reserved[8];
struct is3_record {
uint32_t address;
uint32_t data;
uint32_t mask;
__be32 address;
__be32 data;
__be32 mask;
} record[18];
} is3_config_space_t;

Expand Down Expand Up @@ -200,11 +200,6 @@ static int do_config_space_records(ib_portid_t *portid, unsigned set,

if (records > 18)
records = 18;
for (i = 0; i < records; i++) {
cs->record[i].address = htonl(cs->record[i].address);
cs->record[i].data = htonl(cs->record[i].data);
cs->record[i].mask = htonl(cs->record[i].mask);
}

if (do_vendor(portid, IB_MLX_VENDOR_CLASS,
set ? IB_MAD_METHOD_SET : IB_MAD_METHOD_GET,
Expand Down Expand Up @@ -293,6 +288,8 @@ static unsigned write_cs_records, read_cs_records;
static int process_opt(void *context, int ch)
{
int ret;
unsigned int address, data, mask;

switch (ch) {
case 'N':
general_info = 1;
Expand All @@ -312,26 +309,26 @@ static int process_opt(void *context, int ch)
case 'R':
if (read_cs_records >= 18)
break;
ret = sscanf(optarg, "%x,%x",
&read_cs.record[read_cs_records].address,
&read_cs.record[read_cs_records].mask);
ret = sscanf(optarg, "%x,%x", &address, &mask);
if (ret < 1)
return -1;
else if (ret == 1)
read_cs.record[read_cs_records].mask = 0xffffffff;
mask = 0xffffffff;
read_cs.record[read_cs_records].address = htobe32(address);
read_cs.record[read_cs_records].mask = htobe32(mask);
read_cs_records++;
break;
case 'W':
if (write_cs_records >= 18)
break;
ret = sscanf(optarg, "%x,%x,%x",
&write_cs.record[write_cs_records].address,
&write_cs.record[write_cs_records].data,
&write_cs.record[write_cs_records].mask);
ret = sscanf(optarg, "%x,%x,%x", &address, &data, &mask);
if (ret < 2)
return -1;
else if (ret == 2)
write_cs.record[write_cs_records].mask = 0xffffffff;
mask = 0xffffffff;
write_cs.record[write_cs_records].address = htobe32(address);
write_cs.record[write_cs_records].data = htobe32(data);
write_cs.record[write_cs_records].mask = htobe32(mask);
write_cs_records++;
break;
default:
Expand Down

0 comments on commit 45a0523

Please sign in to comment.