diff mbox

[07/14] ibacm: convert logging in acm_util.c to acm_log

Message ID 1396572714-16498-8-git-send-email-ira.weiny@intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Ira Weiny April 4, 2014, 12:51 a.m. UTC
From: Ira Weiny <ira.weiny@intel.com>

ib_acme build defines ACME_PRINTS which overrides acm_log to printf

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 Makefile.am    |    2 +-
 src/acm.c      |    6 ++----
 src/acm_util.c |   21 +++++++++------------
 src/acm_util.h |   12 ++++++++++++
 4 files changed, 24 insertions(+), 17 deletions(-)
diff mbox

Patch

diff --git a/Makefile.am b/Makefile.am
index 539ef83..703030d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,7 +8,7 @@  svc_ibacm_SOURCES = src/acm.c
 util_ib_acme_SOURCES = src/acme.c linux/acme_linux.c src/libacm.c linux/libacm_linux.c \
 			src/parse.c src/acm_util.c
 svc_ibacm_CFLAGS = $(AM_CFLAGS)
-util_ib_acme_CFLAGS = $(AM_CFLAGS)
+util_ib_acme_CFLAGS = $(AM_CFLAGS) -DACME_PRINTS
 
 ibacmincludedir = $(includedir)/infiniband
 
diff --git a/src/acm.c b/src/acm.c
index 82f9431..5dc2684 100644
--- a/src/acm.c
+++ b/src/acm.c
@@ -47,6 +47,7 @@ 
 #include <dlist.h>
 #include <search.h>
 #include "acm_mad.h"
+#include "acm_util.h"
 
 #define src_out     data[0]
 
@@ -245,10 +246,7 @@  static uint8_t min_rate = IBV_RATE_10_GBPS;
 static enum acm_route_preload route_preload;
 static enum acm_addr_preload addr_preload;
 
-#define acm_log(level, format, ...) \
-	acm_write(level, "%s: "format, __func__, ## __VA_ARGS__)
-
-static void acm_write(int level, const char *format, ...)
+void acm_write(int level, const char *format, ...)
 {
 	va_list args;
 	struct timeval tv;
diff --git a/src/acm_util.c b/src/acm_util.c
index 922eceb..7a84ac7 100644
--- a/src/acm_util.c
+++ b/src/acm_util.c
@@ -52,7 +52,7 @@  int acm_if_is_ib(char *ifname)
 	snprintf(buf, sizeof buf, "//sys//class//net//%s//type", ifname);
 	f = fopen(buf, "r");
 	if (!f) {
-		printf("failed to open %s\n", buf);
+		acm_log(0, "failed to open %s\n", buf);
 		return 0;
 	}
 
@@ -60,6 +60,7 @@  int acm_if_is_ib(char *ifname)
 		type = strtol(buf, NULL, 0);
 		ret = (type == ARPHRD_INFINIBAND);
 	} else {
+		acm_log(0, "failed to read interface type\n");
 		ret = 0;
 	}
 
@@ -76,7 +77,7 @@  int acm_if_get_pkey(char *ifname, uint16_t *pkey)
 	snprintf(buf, sizeof buf, "//sys//class//net//%s//pkey", ifname);
 	f = fopen(buf, "r");
 	if (!f) {
-		printf("failed to open %s\n", buf);
+		acm_log(0, "failed to open %s\n", buf);
 		return -1;
 	}
 
@@ -84,7 +85,7 @@  int acm_if_get_pkey(char *ifname, uint16_t *pkey)
 		*pkey = strtol(buf, &end, 16);
 		ret = 0;
 	} else {
-		printf("failed to read pkey\n");
+		acm_log(0, "failed to read pkey\n");
 		ret = -1;
 	}
 
@@ -101,7 +102,7 @@  int acm_if_get_sgid(char *ifname, union ibv_gid *sgid)
 	snprintf(buf, sizeof buf, "//sys//class//net//%s//address", ifname);
 	f = fopen(buf, "r");
 	if (!f) {
-		printf("failed to open %s\n", buf);
+		acm_log(0, "failed to open %s\n", buf);
 		return -1;
 	}
 
@@ -112,7 +113,7 @@  int acm_if_get_sgid(char *ifname, union ibv_gid *sgid)
 		}
 		ret = 0;
 	} else {
-		printf("failed to read sgid\n");
+		acm_log(0, "failed to read sgid\n");
 		ret = -1;
 	}
 
@@ -146,7 +147,7 @@  int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx)
 
 	ret = ioctl(s, SIOCGIFCONF, ifc);
 	if (ret < 0) {
-		printf("ioctl ifconf error %d\n", ret);
+		acm_log(0, "ioctl ifconf error %d\n", ret);
 		goto out2;
 	}
 
@@ -169,16 +170,12 @@  int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx)
 			continue;
 
 		ret = acm_if_get_sgid(ifr[i].ifr_name, &sgid);
-		if (ret) {
-			printf("unable to get sgid\n");
+		if (ret)
 			continue;
-		}
 
 		ret = acm_if_get_pkey(ifr[i].ifr_name, &pkey);
-		if (ret) {
-			printf("unable to get pkey\n");
+		if (ret)
 			continue;
-		}
 
 		cb(ifr[i].ifr_name, &sgid, pkey, 0, NULL, 0, ip, ctx);
 	}
diff --git a/src/acm_util.h b/src/acm_util.h
index ea86133..4f111b6 100644
--- a/src/acm_util.h
+++ b/src/acm_util.h
@@ -32,6 +32,18 @@ 
 
 #include <infiniband/verbs.h>
 
+#ifdef ACME_PRINTS
+
+#define acm_log(level, format, ...) \
+	printf(format, ## __VA_ARGS__)
+
+#else /* !ACME_PRINTS */
+#define acm_log(level, format, ...) \
+	acm_write(level, "%s: "format, __func__, ## __VA_ARGS__)
+
+void acm_write(int level, const char *format, ...);
+#endif /* ACME_PRINTS */
+
 int acm_if_is_ib(char *ifname);
 int acm_if_get_pkey(char *ifname, uint16_t *pkey);
 int acm_if_get_sgid(char *ifname, union ibv_gid *sgid);