[ofa-general] [PATCH] libibmad: cleanup deprecated function use
Sasha Khapyorsky
sashak at voltaire.com
Sat Mar 7 13:48:15 PST 2009
This cleans up libibmad internal stuff from using potentially deprecated
functions, which may go away soon.
Also removes DEPRECATED attribute from mad_register_port_client() - it
doesn't touch any global data.
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
libibmad/include/infiniband/mad.h | 3 +-
libibmad/src/gs.c | 12 +-----
libibmad/src/libibmad.map | 1 -
libibmad/src/mad_internal.h | 2 +
libibmad/src/register.c | 68 ++++---------------------------------
libibmad/src/resolve.c | 7 ++--
libibmad/src/rpc.c | 41 +++++++--------------
libibmad/src/sa.c | 15 +++++---
libibmad/src/serv.c | 19 ++---------
libibmad/src/smp.c | 17 +++------
libibmad/src/vendor.c | 6 +---
11 files changed, 48 insertions(+), 143 deletions(-)
diff --git a/libibmad/include/infiniband/mad.h b/libibmad/include/infiniband/mad.h
index ed2412c..064cbb7 100644
--- a/libibmad/include/infiniband/mad.h
+++ b/libibmad/include/infiniband/mad.h
@@ -745,7 +745,7 @@ MAD_EXPORT int mad_rpc_portid(struct ibmad_port *srcport);
/* register.c */
MAD_EXPORT int mad_register_port_client(int port_id, int mgmt,
- uint8_t rmpp_version) DEPRECATED;
+ uint8_t rmpp_version);
MAD_EXPORT int mad_register_client(int mgmt, uint8_t rmpp_version)
DEPRECATED;
MAD_EXPORT int mad_register_server(int mgmt, uint8_t rmpp_version,
@@ -759,7 +759,6 @@ MAD_EXPORT int mad_register_server_via(int mgmt, uint8_t rmpp_version,
uint32_t class_oui,
struct ibmad_port *srcport);
MAD_EXPORT int mad_class_agent(int mgmt);
-MAD_EXPORT int mad_agent_class(int agent);
/* serv.c */
MAD_EXPORT int mad_send(ib_rpc_t * rpc, ib_portid_t * dport,
diff --git a/libibmad/src/gs.c b/libibmad/src/gs.c
index 132187a..dbca9e9 100644
--- a/libibmad/src/gs.c
+++ b/libibmad/src/gs.c
@@ -74,11 +74,7 @@ uint8_t *pma_query_via(void *rcvbuf, ib_portid_t * dest, int port,
if (!dest->qkey)
dest->qkey = IB_DEFAULT_QP1_QKEY;
- if (srcport) {
- return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf);
- } else {
- return madrpc(&rpc, dest, rcvbuf, rcvbuf);
- }
+ return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf);
}
uint8_t *performance_reset_via(void *rcvbuf, ib_portid_t * dest,
@@ -117,9 +113,5 @@ uint8_t *performance_reset_via(void *rcvbuf, ib_portid_t * dest,
if (!dest->qkey)
dest->qkey = IB_DEFAULT_QP1_QKEY;
- if (srcport) {
- return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf);
- } else {
- return madrpc(&rpc, dest, rcvbuf, rcvbuf);
- }
+ return mad_rpc(srcport, &rpc, dest, rcvbuf, rcvbuf);
}
diff --git a/libibmad/src/libibmad.map b/libibmad/src/libibmad.map
index 70f6f0f..0be7a92 100644
--- a/libibmad/src/libibmad.map
+++ b/libibmad/src/libibmad.map
@@ -53,7 +53,6 @@ IBMAD_1.3 {
portid2str;
str2drpath;
drpath2str;
- mad_agent_class;
mad_class_agent;
mad_register_client;
mad_register_server;
diff --git a/libibmad/src/mad_internal.h b/libibmad/src/mad_internal.h
index 9afe7a9..e948540 100644
--- a/libibmad/src/mad_internal.h
+++ b/libibmad/src/mad_internal.h
@@ -41,4 +41,6 @@ struct ibmad_port {
int class_agents[MAX_CLASS]; /* class2agent mapper */
};
+extern struct ibmad_port *ibmp;
+
#endif /* _MAD_INTERNAL_H_ */
diff --git a/libibmad/src/register.c b/libibmad/src/register.c
index 4aabd7c..eb8a62e 100644
--- a/libibmad/src/register.c
+++ b/libibmad/src/register.c
@@ -48,33 +48,6 @@
#undef DEBUG
#define DEBUG if (ibdebug) IBWARN
-#define MAX_AGENTS 256
-
-static int class_agent[MAX_CLASS];
-static int agent_class[MAX_AGENTS];
-
-static int register_agent(int agent, int mclass)
-{
- static int initialized;
-
- if (!initialized) {
- initialized++;
- memset(class_agent, 0xff, sizeof class_agent);
- memset(agent_class, 0xff, sizeof agent_class);
- }
-
- if (mclass < 0 || mclass >= MAX_CLASS ||
- agent < 0 || agent >= MAX_AGENTS) {
- DEBUG("bad mgmt class %d or agent %d", mclass, agent);
- return -1;
- }
-
- class_agent[mclass] = agent;
- agent_class[agent] = mclass;
-
- return 0;
-}
-
static int mgmt_class_vers(int mgmt_class)
{
if ((mgmt_class >= IB_VENDOR_RANGE1_START_CLASS &&
@@ -104,14 +77,7 @@ int mad_class_agent(int mgmt)
{
if (mgmt < 1 || mgmt > MAX_CLASS)
return -1;
- return class_agent[mgmt];
-}
-
-int mad_agent_class(int agent)
-{
- if (agent < 1 || agent > MAX_AGENTS)
- return -1;
- return agent_class[agent];
+ return ibmp->class_agents[mgmt];
}
int mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version)
@@ -122,14 +88,10 @@ int mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version)
DEBUG("Unknown class %d mgmt_class", mgmt);
return -1;
}
- if ((agent = umad_register(port_id, mgmt, vers, rmpp_version, 0)) < 0) {
- DEBUG("Can't register agent for class %d", mgmt);
- return -1;
- }
- if (mgmt < 0 || mgmt >= MAX_CLASS || agent >= MAX_AGENTS) {
- DEBUG("bad mgmt class %d or agent %d", mgmt, agent);
- return -1;
+ agent = umad_register(port_id, mgmt, vers, rmpp_version, 0);
+ if (agent < 0) {
+ DEBUG("Can't register agent for class %d", mgmt);
}
return agent;
@@ -137,14 +99,7 @@ int mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version)
int mad_register_client(int mgmt, uint8_t rmpp_version)
{
- int rc = 0;
- struct ibmad_port port;
-
- port.port_id = madrpc_portid();
- rc = mad_register_client_via(mgmt, rmpp_version, &port);
- if (rc < 0)
- return rc;
- return register_agent(port.class_agents[mgmt], mgmt);
+ return mad_register_client_via(mgmt, rmpp_version, ibmp);
}
int mad_register_client_via(int mgmt, uint8_t rmpp_version,
@@ -167,17 +122,8 @@ int
mad_register_server(int mgmt, uint8_t rmpp_version,
long method_mask[], uint32_t class_oui)
{
- int rc = 0;
- struct ibmad_port port;
-
- port.port_id = madrpc_portid();
- port.class_agents[mgmt] = class_agent[mgmt];
- rc = mad_register_server_via(mgmt, rmpp_version,
- method_mask, class_oui,
- &port);
- if (rc < 0)
- return rc;
- return register_agent(port.class_agents[mgmt], mgmt);
+ return mad_register_server_via(mgmt, rmpp_version, method_mask,
+ class_oui, ibmp);
}
int
diff --git a/libibmad/src/resolve.c b/libibmad/src/resolve.c
index 3291f43..f34c247 100644
--- a/libibmad/src/resolve.c
+++ b/libibmad/src/resolve.c
@@ -41,6 +41,7 @@
#include <infiniband/umad.h>
#include <infiniband/mad.h>
+#include "mad_internal.h"
#undef DEBUG
#define DEBUG if (ibdebug) IBWARN
@@ -64,7 +65,7 @@ int ib_resolve_smlid_via(ib_portid_t * sm_id, int timeout,
int ib_resolve_smlid(ib_portid_t * sm_id, int timeout)
{
- return ib_resolve_smlid_via(sm_id, timeout, NULL);
+ return ib_resolve_smlid_via(sm_id, timeout, ibmp);
}
int ib_resolve_guid_via(ib_portid_t * portid, uint64_t * guid,
@@ -148,7 +149,7 @@ int ib_resolve_portid_str(ib_portid_t * portid, char *addr_str,
enum MAD_DEST dest_type, ib_portid_t * sm_id)
{
return ib_resolve_portid_str_via(portid, addr_str, dest_type,
- sm_id, NULL);
+ sm_id, ibmp);
}
int ib_resolve_self_via(ib_portid_t * portid, int *portnum, ibmad_gid_t * gid,
@@ -180,5 +181,5 @@ int ib_resolve_self_via(ib_portid_t * portid, int *portnum, ibmad_gid_t * gid,
int ib_resolve_self(ib_portid_t * portid, int *portnum, ibmad_gid_t * gid)
{
- return ib_resolve_self_via(portid, portnum, gid, NULL);
+ return ib_resolve_self_via(portid, portnum, gid, ibmp);
}
diff --git a/libibmad/src/rpc.c b/libibmad/src/rpc.c
index 210f0c2..8c68cf9 100644
--- a/libibmad/src/rpc.c
+++ b/libibmad/src/rpc.c
@@ -47,7 +47,9 @@
int ibdebug;
-static int mad_portid = -1;
+static struct ibmad_port mad_port;
+struct ibmad_port *ibmp = &mad_port;
+
static int iberrs;
static int madrpc_retries = MAD_DEF_RETRIES;
@@ -92,7 +94,7 @@ int madrpc_def_timeout(void)
int madrpc_portid(void)
{
- return mad_portid;
+ return ibmp->port_id;
}
int mad_rpc_portid(struct ibmad_port *srcport)
@@ -260,42 +262,38 @@ void *mad_rpc_rmpp(const struct ibmad_port *port, ib_rpc_t * rpc, ib_portid_t *
void *madrpc(ib_rpc_t * rpc, ib_portid_t * dport, void *payload, void *rcvdata)
{
- struct ibmad_port port;
-
- port.port_id = mad_portid;
- port.class_agents[rpc->mgtclass] = mad_class_agent(rpc->mgtclass);
- return mad_rpc(&port, rpc, dport, payload, rcvdata);
+ return mad_rpc(ibmp, rpc, dport, payload, rcvdata);
}
void *madrpc_rmpp(ib_rpc_t * rpc, ib_portid_t * dport, ib_rmpp_hdr_t * rmpp,
void *data)
{
- struct ibmad_port port;
-
- port.port_id = mad_portid;
- port.class_agents[rpc->mgtclass] = mad_class_agent(rpc->mgtclass);
- return mad_rpc_rmpp(&port, rpc, dport, rmpp, data);
+ return mad_rpc_rmpp(ibmp, rpc, dport, rmpp, data);
}
void
madrpc_init(char *dev_name, int dev_port, int *mgmt_classes, int num_classes)
{
+ int fd;
+
if (umad_init() < 0)
IBPANIC("can't init UMAD library");
- if ((mad_portid = umad_open_port(dev_name, dev_port)) < 0)
+ if ((fd = umad_open_port(dev_name, dev_port)) < 0)
IBPANIC("can't open UMAD port (%s:%d)", dev_name, dev_port);
if (num_classes >= MAX_CLASS)
IBPANIC("too many classes %d requested", num_classes);
+ ibmp->port_id = fd;
+ memset(ibmp->class_agents, 0xff, sizeof ibmp->class_agents);
while (num_classes--) {
uint8_t rmpp_version = 0;
int mgmt = *mgmt_classes++;
if (mgmt == IB_SA_CLASS)
rmpp_version = 1;
- if (mad_register_client(mgmt, rmpp_version) < 0)
+ if (mad_register_client_via(mgmt, rmpp_version, ibmp) < 0)
IBPANIC("client_register for mgmt class %d failed",
mgmt);
}
@@ -334,6 +332,7 @@ struct ibmad_port *mad_rpc_open_port(char *dev_name, int dev_port,
return NULL;
}
+ p->port_id = port_id;
memset(p->class_agents, 0xff, sizeof p->class_agents);
while (num_classes--) {
uint8_t rmpp_version = 0;
@@ -343,8 +342,7 @@ struct ibmad_port *mad_rpc_open_port(char *dev_name, int dev_port,
if (mgmt == IB_SA_CLASS)
rmpp_version = 1;
if (mgmt < 0 || mgmt >= MAX_CLASS ||
- (agent = mad_register_port_client(port_id, mgmt,
- rmpp_version)) < 0) {
+ (agent = mad_register_client_via(mgmt, rmpp_version, p)) < 0) {
IBWARN("client_register for mgmt %d failed", mgmt);
if (!errno)
errno = EINVAL;
@@ -355,7 +353,6 @@ struct ibmad_port *mad_rpc_open_port(char *dev_name, int dev_port,
p->class_agents[mgmt] = agent;
}
- p->port_id = port_id;
return p;
}
@@ -364,13 +361,3 @@ void mad_rpc_close_port(struct ibmad_port *port)
umad_close_port(port->port_id);
free(port);
}
-
-uint8_t *sa_call(void *rcvbuf, ib_portid_t * portid, ib_sa_call_t * sa,
- unsigned timeout)
-{
- struct ibmad_port port;
-
- port.port_id = mad_portid;
- port.class_agents[IB_SA_CLASS] = mad_class_agent(IB_SA_CLASS);
- return sa_rpc_call(&port, rcvbuf, portid, sa, timeout);
-}
diff --git a/libibmad/src/sa.c b/libibmad/src/sa.c
index ddeb152..5174bb5 100644
--- a/libibmad/src/sa.c
+++ b/libibmad/src/sa.c
@@ -40,6 +40,7 @@
#include <string.h>
#include <infiniband/mad.h>
+#include "mad_internal.h"
#undef DEBUG
#define DEBUG if (ibdebug) IBWARN
@@ -79,6 +80,12 @@ uint8_t *sa_rpc_call(const struct ibmad_port *ibmad_port, void *rcvbuf, ib_porti
return p;
}
+uint8_t *sa_call(void *rcvbuf, ib_portid_t * portid, ib_sa_call_t * sa,
+ unsigned timeout)
+{
+ return sa_rpc_call(ibmp, rcvbuf, portid, sa, timeout);
+}
+
/* PathRecord */
#define IB_PR_COMPMASK_DGID (1ull<<2)
#define IB_PR_COMPMASK_SGID (1ull<<3)
@@ -127,11 +134,7 @@ int ib_path_query_via(const struct ibmad_port *srcport, ibmad_gid_t srcgid,
mad_encode_field(buf, IB_SA_PR_DGID_F, destgid);
mad_encode_field(buf, IB_SA_PR_SGID_F, srcgid);
- if (srcport) {
- p = sa_rpc_call(srcport, buf, sm_id, &sa, 0);
- } else {
- p = sa_call(buf, sm_id, &sa, 0);
- }
+ p = sa_rpc_call(srcport, buf, sm_id, &sa, 0);
if (!p) {
IBWARN("sa call path_query failed");
return -1;
@@ -144,5 +147,5 @@ int ib_path_query_via(const struct ibmad_port *srcport, ibmad_gid_t srcgid,
int ib_path_query(ibmad_gid_t srcgid, ibmad_gid_t destgid, ib_portid_t * sm_id,
void *buf)
{
- return ib_path_query_via(NULL, srcgid, destgid, sm_id, buf);
+ return ib_path_query_via(ibmp, srcgid, destgid, sm_id, buf);
}
diff --git a/libibmad/src/serv.c b/libibmad/src/serv.c
index 0ce1660..c97466a 100644
--- a/libibmad/src/serv.c
+++ b/libibmad/src/serv.c
@@ -50,11 +50,7 @@
int
mad_send(ib_rpc_t * rpc, ib_portid_t * dport, ib_rmpp_hdr_t * rmpp, void *data)
{
- struct ibmad_port port;
-
- port.port_id = madrpc_portid();
- port.class_agents[rpc->mgtclass] = mad_class_agent(rpc->mgtclass);
- return mad_send_via(rpc, dport, rmpp, data, &port);
+ return mad_send_via(rpc, dport, rmpp, data, ibmp);
}
int
@@ -88,13 +84,7 @@ mad_send_via(ib_rpc_t * rpc, ib_portid_t * dport, ib_rmpp_hdr_t * rmpp, void *da
int mad_respond(void *umad, ib_portid_t * portid, uint32_t rstatus)
{
- int i = 0;
- struct ibmad_port port;
-
- port.port_id = madrpc_portid();
- for (i = 1; i < MAX_CLASS; i++)
- port.class_agents[i] = mad_class_agent(i);
- return mad_respond_via(umad, portid, rstatus, &port);
+ return mad_respond_via(umad, portid, rstatus, ibmp);
}
int mad_respond_via(void *umad, ib_portid_t * portid, uint32_t rstatus,
@@ -174,10 +164,7 @@ int mad_respond_via(void *umad, ib_portid_t * portid, uint32_t rstatus,
void *mad_receive(void *umad, int timeout)
{
- struct ibmad_port port;
-
- port.port_id = madrpc_portid();
- return mad_receive_via(umad, timeout, &port);
+ return mad_receive_via(umad, timeout, ibmp);
}
void *mad_receive_via(void *umad, int timeout, struct ibmad_port *srcport)
diff --git a/libibmad/src/smp.c b/libibmad/src/smp.c
index e5489b3..4983786 100644
--- a/libibmad/src/smp.c
+++ b/libibmad/src/smp.c
@@ -40,6 +40,7 @@
#include <string.h>
#include <infiniband/mad.h>
+#include "mad_internal.h"
#undef DEBUG
#define DEBUG if (ibdebug) IBWARN
@@ -67,17 +68,13 @@ uint8_t *smp_set_via(void *data, ib_portid_t * portid, unsigned attrid,
portid->sl = 0;
portid->qp = 0;
- if (srcport) {
- return mad_rpc(srcport, &rpc, portid, data, data);
- } else {
- return madrpc(&rpc, portid, data, data);
- }
+ return mad_rpc(srcport, &rpc, portid, data, data);
}
uint8_t *smp_set(void *data, ib_portid_t * portid, unsigned attrid,
unsigned mod, unsigned timeout)
{
- return smp_set_via(data, portid, attrid, mod, timeout, NULL);
+ return smp_set_via(data, portid, attrid, mod, timeout, ibmp);
}
uint8_t *smp_query_via(void *rcvbuf, ib_portid_t * portid, unsigned attrid,
@@ -103,15 +100,11 @@ uint8_t *smp_query_via(void *rcvbuf, ib_portid_t * portid, unsigned attrid,
portid->sl = 0;
portid->qp = 0;
- if (srcport) {
- return mad_rpc(srcport, &rpc, portid, 0, rcvbuf);
- } else {
- return madrpc(&rpc, portid, 0, rcvbuf);
- }
+ return mad_rpc(srcport, &rpc, portid, 0, rcvbuf);
}
uint8_t *smp_query(void *rcvbuf, ib_portid_t * portid, unsigned attrid,
unsigned mod, unsigned timeout)
{
- return smp_query_via(rcvbuf, portid, attrid, mod, timeout, NULL);
+ return smp_query_via(rcvbuf, portid, attrid, mod, timeout, ibmp);
}
diff --git a/libibmad/src/vendor.c b/libibmad/src/vendor.c
index 2610976..31726fc 100644
--- a/libibmad/src/vendor.c
+++ b/libibmad/src/vendor.c
@@ -54,11 +54,7 @@ static inline int response_expected(int method)
uint8_t *ib_vendor_call(void *data, ib_portid_t * portid,
ib_vendor_call_t * call)
{
- struct ibmad_port port;
-
- port.port_id = madrpc_portid();
- port.class_agents[call->mgmt_class] = mad_class_agent(call->mgmt_class);
- return ib_vendor_call_via(data, portid, call, &port);
+ return ib_vendor_call_via(data, portid, call, ibmp);
}
uint8_t *ib_vendor_call_via(void *data, ib_portid_t * portid,
--
1.6.1.2.319.gbd9e
More information about the general
mailing list