>From 0aec877fb0d773a98a9d628aa1d9a89062ab0b9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
Date: Mon, 10 Aug 2015 18:35:16 +0200
Subject: [PATCH] DEBUG: Add new debug category for fail over.

---
 src/providers/data_provider_fo.c | 30 ++++++++++++++++++++++++++----
 src/providers/dp_backend.h       | 15 +++++++++++----
 src/tests/debug-tests.c          |  2 +-
 src/util/debug.c                 |  2 +-
 src/util/util.h                  |  1 +
 5 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/src/providers/data_provider_fo.c b/src/providers/data_provider_fo.c
index dab796d..41d70de 100644
--- a/src/providers/data_provider_fo.c
+++ b/src/providers/data_provider_fo.c
@@ -743,13 +743,35 @@ void reset_fo(struct be_ctx *be_ctx)
     fo_reset_services(be_ctx->be_fo->fo_ctx);
 }
 
-void be_fo_set_port_status(struct be_ctx *ctx,
-                           const char *service_name,
-                           struct fo_server *server,
-                           enum port_status status)
+void _be_fo_set_port_status(struct be_ctx *ctx,
+                            const char *service_name,
+                            struct fo_server *server,
+                            enum port_status status,
+                            int line,
+                            const char *file,
+                            const char *function)
 {
     struct be_svc_data *be_svc;
 
+    /* Print debug info */
+    switch (status) {
+    case PORT_NEUTRAL:
+        DEBUG(SSSDBG_BE_FO,
+              "Setting status: PORT_NEUTRAL. Called from: %s: %s: %d\n",
+              file, function, line);
+        break;
+    case PORT_WORKING:
+        DEBUG(SSSDBG_BE_FO,
+              "Setting status: PORT_WORKING. Called from: %s: %s: %d\n",
+              file, function, line);
+        break;
+    case PORT_NOT_WORKING:
+        DEBUG(SSSDBG_BE_FO,
+              "Setting status: PORT_NOT_WORKING. Called from: %s: %s: %d\n",
+              file, function, line);
+        break;
+    }
+
     be_svc = be_fo_find_svc_data(ctx, service_name);
     if (be_svc == NULL) {
         DEBUG(SSSDBG_OP_FAILURE,
diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h
index e4e22ea..bca0c2f 100644
--- a/src/providers/dp_backend.h
+++ b/src/providers/dp_backend.h
@@ -259,10 +259,17 @@ struct tevent_req *be_resolve_server_send(TALLOC_CTX *memctx,
                                           bool first_try);
 int be_resolve_server_recv(struct tevent_req *req, struct fo_server **srv);
 
-void be_fo_set_port_status(struct be_ctx *ctx,
-                           const char *service_name,
-                           struct fo_server *server,
-                           enum port_status status);
+#define be_fo_set_port_status(ctx, service_name, server, status) \
+    _be_fo_set_port_status(ctx, service_name, server, status, \
+                           __LINE__, __FILE__, __FUNCTION__)
+
+void _be_fo_set_port_status(struct be_ctx *ctx,
+                            const char *service_name,
+                            struct fo_server *server,
+                            enum port_status status,
+                            int line,
+                            const char *file,
+                            const char *function);
 
 /*
  * Instruct fail-over to try next server on the next connect attempt.
diff --git a/src/tests/debug-tests.c b/src/tests/debug-tests.c
index 2b91c14..067209b 100644
--- a/src/tests/debug-tests.c
+++ b/src/tests/debug-tests.c
@@ -48,7 +48,7 @@ START_TEST(test_debug_convert_old_level_old_format)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL | SSSDBG_BE_FO
     };
 
     for (old_level = 0; old_level <= 9; old_level++) {
diff --git a/src/util/debug.c b/src/util/debug.c
index bf83624..69df543 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -114,7 +114,7 @@ int debug_convert_old_level(int old_level)
         new_level |= SSSDBG_TRACE_INTERNAL;
 
     if (old_level >= 9)
-        new_level |= SSSDBG_TRACE_ALL;
+        new_level |= SSSDBG_TRACE_ALL | SSSDBG_BE_FO;
 
     return new_level;
 }
diff --git a/src/util/util.h b/src/util/util.h
index 94a3dde..426fd8b 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -92,6 +92,7 @@ int get_fd_from_debug_file(void);
 #define SSSDBG_TRACE_LIBS     0x1000   /* level 7 */
 #define SSSDBG_TRACE_INTERNAL 0x2000   /* level 8 */
 #define SSSDBG_TRACE_ALL      0x4000   /* level 9 */
+#define SSSDBG_BE_FO          0x8000   /* level 9 */
 #define SSSDBG_IMPORTANT_INFO SSSDBG_OP_FAILURE
 
 #define SSSDBG_INVALID        -1
-- 
2.1.0

