]> git.openfabrics.org - ~shefty/ibacm.git/commitdiff
ibacm: convert logging in acm_util.c to acm_log
authorIra Weiny <ira.weiny@intel.com>
Tue, 25 Mar 2014 07:07:35 +0000 (03:07 -0400)
committerSean Hefty <sean.hefty@intel.com>
Tue, 8 Apr 2014 21:09:22 +0000 (14:09 -0700)
ib_acme build defines ACME_PRINTS which overrides acm_log to printf

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
Makefile.am
src/acm.c
src/acm_util.c
src/acm_util.h

index 539ef831e3ae0d5adf865c9fb32b34c082475fb2..703030d26675e9bc4333699cebc6764da4cf5036 100644 (file)
@@ -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
 
index 82f943188b801cdd14c86567f3616009e5d347b7..5dc268411f353de641ba07a965847a78e4cacd58 100644 (file)
--- 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;
index 922eceb2428e830334aff58a1099e64069e5599b..7a84ac7935fcc00333e4d9b176aac68da4f66416 100644 (file)
@@ -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);
        }
index ea86133b45eda0cb1bac1b7fda0a3d319dab356d..4f111b6f52933ebcce47581d654e03cb9a883c6e 100644 (file)
 
 #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);