Blob Blame History Raw
From 902c8931f51d4ca17147901ff542a71d7c434f01 Mon Sep 17 00:00:00 2001
From: Alexey Tikhonov <atikhono@redhat.com>
Date: Tue, 5 May 2020 18:26:52 +0200
Subject: [PATCH 23/25] DEBUG: introduce new SSSDBG_TRACE_LDB level
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

libldb LDB_DEBUG_TRACE messages usually doesn't bring any useful info
but create a lot of unneeded noise in the logs.
Nonetheless it feels too radical to drop them completely.
This patch introduces new debug_level=10 (0x10000) especially for those
messages.

Reviewed-by: Pawel Polawski <ppolawsk@redhat.com>
(cherry picked from commit b5604d072e93bca7fc0c408fcfbb88f41c4d50ca)

Reviewed-by: Pavel Březina <pbrezina@redhat.com>

Reviewed-by: Pavel Březina <pbrezina@redhat.com>
---
 src/man/include/debug_levels.xml       |  5 +++
 src/man/include/debug_levels_tools.xml |  5 +++
 src/tests/debug-tests.c                | 49 ++++++++++++++++----------
 src/util/debug.c                       |  5 ++-
 src/util/debug.h                       |  7 +++-
 5 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/src/man/include/debug_levels.xml b/src/man/include/debug_levels.xml
index 93a8ec901..b5e13ba3e 100644
--- a/src/man/include/debug_levels.xml
+++ b/src/man/include/debug_levels.xml
@@ -77,6 +77,11 @@
          <emphasis>9</emphasis>,
          <emphasis>0x4000</emphasis>: Extremely low-level tracing information.
     </para>
+    <para>
+         <emphasis>10</emphasis>,
+         <emphasis>0x10000</emphasis>: Even more low-level libldb tracing
+         information. Almost never really required.
+    </para>
     <para>
         To log required bitmask debug levels, simply add their numbers together
         as shown in following examples:
diff --git a/src/man/include/debug_levels_tools.xml b/src/man/include/debug_levels_tools.xml
index fcc0c2d8b..b592d50fc 100644
--- a/src/man/include/debug_levels_tools.xml
+++ b/src/man/include/debug_levels_tools.xml
@@ -58,6 +58,11 @@
          <emphasis>9</emphasis>,
          <emphasis>0x4000</emphasis>: Extremely low-level tracing information.
     </para>
+    <para>
+         <emphasis>10</emphasis>,
+         <emphasis>0x10000</emphasis>: Even more low-level libldb tracing
+         information. Almost never really required.
+    </para>
     <para>
         To log required bitmask debug levels, simply add their numbers together
         as shown in following examples:
diff --git a/src/tests/debug-tests.c b/src/tests/debug-tests.c
index 95b0a8f00..1e78f506e 100644
--- a/src/tests/debug-tests.c
+++ b/src/tests/debug-tests.c
@@ -48,10 +48,11 @@ START_TEST(test_debug_convert_old_level_old_format)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL | SSSDBG_BE_FO
+        SSSDBG_TRACE_ALL | SSSDBG_BE_FO,
+        SSSDBG_TRACE_LDB
     };
 
-    for (old_level = 0; old_level <= 9; old_level++) {
+    for (old_level = 0; old_level < N_ELEMENTS(levels); old_level++) {
         expected_level |= levels[old_level];
 
         char *msg = NULL;
@@ -108,6 +109,10 @@ START_TEST(test_debug_convert_old_level_new_format)
         debug_convert_old_level(SSSDBG_TRACE_ALL) == SSSDBG_TRACE_ALL,
         "Invalid conversion of SSSDBG_TRACE_ALL"
     );
+    fail_unless(
+        debug_convert_old_level(SSSDBG_TRACE_LDB) == SSSDBG_TRACE_LDB,
+        "Invalid conversion of SSSDBG_TRACE_LDB"
+    );
     fail_unless(
         debug_convert_old_level(SSSDBG_MASK_ALL) == SSSDBG_MASK_ALL,
         "Invalid conversion of SSSDBG_MASK_ALL"
@@ -335,7 +340,8 @@ START_TEST(test_debug_is_set_single_no_timestamp)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL,
+        SSSDBG_TRACE_LDB
     };
     char *error_msg;
 
@@ -345,7 +351,7 @@ START_TEST(test_debug_is_set_single_no_timestamp)
     debug_prg_name = "sssd";
     sss_set_logger(sss_logger_str[FILES_LOGGER]);
 
-    for (i = 0; i <= 9; i++) {
+    for (i = 0; i < N_ELEMENTS(levels); i++) {
         debug_level = levels[i];
 
         errno = 0;
@@ -378,7 +384,8 @@ START_TEST(test_debug_is_set_single_timestamp)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL,
+        SSSDBG_TRACE_LDB
     };
     char *error_msg;
 
@@ -389,7 +396,7 @@ START_TEST(test_debug_is_set_single_timestamp)
     sss_set_logger(sss_logger_str[FILES_LOGGER]);
 
 
-    for (i = 0; i <= 9; i++) {
+    for (i = 0; i < N_ELEMENTS(levels); i++) {
         debug_level = levels[i];
 
         errno = 0;
@@ -427,7 +434,8 @@ START_TEST(test_debug_is_set_single_timestamp_microseconds)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL,
+        SSSDBG_TRACE_LDB
     };
     char *error_msg;
 
@@ -438,7 +446,7 @@ START_TEST(test_debug_is_set_single_timestamp_microseconds)
     sss_set_logger(sss_logger_str[FILES_LOGGER]);
 
 
-    for (i = 0; i <= 9; i++) {
+    for (i = 0; i < N_ELEMENTS(levels); i++) {
         debug_level = levels[i];
 
         errno = 0;
@@ -477,7 +485,8 @@ START_TEST(test_debug_is_notset_no_timestamp)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL,
+        SSSDBG_TRACE_LDB
     };
     char *error_msg;
 
@@ -488,7 +497,7 @@ START_TEST(test_debug_is_notset_no_timestamp)
     sss_set_logger(sss_logger_str[FILES_LOGGER]);
 
 
-    for (i = 0; i <= 9; i++) {
+    for (i = 0; i < N_ELEMENTS(levels); i++) {
         debug_level = all_set & ~levels[i];
 
         errno = 0;
@@ -524,7 +533,8 @@ START_TEST(test_debug_is_notset_timestamp)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL,
+        SSSDBG_TRACE_LDB
     };
     char *error_msg;
 
@@ -535,7 +545,7 @@ START_TEST(test_debug_is_notset_timestamp)
     sss_set_logger(sss_logger_str[FILES_LOGGER]);
 
 
-    for (i = 0; i <= 9; i++) {
+    for (i = 0; i < N_ELEMENTS(levels); i++) {
         debug_level = all_set & ~levels[i];
 
         errno = 0;
@@ -571,7 +581,8 @@ START_TEST(test_debug_is_notset_timestamp_microseconds)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL,
+        SSSDBG_TRACE_LDB
     };
     char *error_msg;
 
@@ -581,7 +592,7 @@ START_TEST(test_debug_is_notset_timestamp_microseconds)
     debug_prg_name = "sssd";
     sss_set_logger(sss_logger_str[FILES_LOGGER]);
 
-    for (i = 0; i <= 9; i++) {
+    for (i = 0; i < N_ELEMENTS(levels); i++) {
         debug_level = all_set & ~levels[i];
 
         errno = 0;
@@ -616,12 +627,13 @@ START_TEST(test_debug_is_set_true)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL,
+        SSSDBG_TRACE_LDB
     };
 
     debug_level = SSSDBG_MASK_ALL;
 
-    for (i = 0; i <= 9; i++) {
+    for (i = 0; i < N_ELEMENTS(levels); i++) {
         result = DEBUG_IS_SET(levels[i]);
         char *msg = NULL;
         msg = talloc_asprintf(NULL, "Test of level %#.4x failed - result is 0x%.4x", levels[i], result);
@@ -646,10 +658,11 @@ START_TEST(test_debug_is_set_false)
         SSSDBG_TRACE_FUNC,
         SSSDBG_TRACE_LIBS,
         SSSDBG_TRACE_INTERNAL,
-        SSSDBG_TRACE_ALL
+        SSSDBG_TRACE_ALL,
+        SSSDBG_TRACE_LDB
     };
 
-    for (i = 0; i <= 9; i++) {
+    for (i = 0; i < N_ELEMENTS(levels); i++) {
         debug_level = all_set & ~levels[i];
 
         result = DEBUG_IS_SET(levels[i]);
diff --git a/src/util/debug.c b/src/util/debug.c
index 0c8e42ad0..e2a76a414 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -170,6 +170,9 @@ int debug_convert_old_level(int old_level)
     if (old_level >= 9)
         new_level |= SSSDBG_TRACE_ALL | SSSDBG_BE_FO;
 
+    if (old_level >= 10)
+        new_level |= SSSDBG_TRACE_LDB;
+
     return new_level;
 }
 
@@ -345,7 +348,7 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level,
         loglevel = SSSDBG_TRACE_FUNC;
         break;
     case LDB_DEBUG_TRACE:
-        loglevel = SSSDBG_TRACE_ALL;
+        loglevel = SSSDBG_TRACE_LDB;
         break;
     }
 
diff --git a/src/util/debug.h b/src/util/debug.h
index 09f50cc9f..134005532 100644
--- a/src/util/debug.h
+++ b/src/util/debug.h
@@ -80,11 +80,16 @@ int get_fd_from_debug_file(void);
 #define SSSDBG_TRACE_INTERNAL 0x2000   /* level 8 */
 #define SSSDBG_TRACE_ALL      0x4000   /* level 9 */
 #define SSSDBG_BE_FO          0x8000   /* level 9 */
+#define SSSDBG_TRACE_LDB     0x10000   /* level 10 */
 #define SSSDBG_IMPORTANT_INFO SSSDBG_OP_FAILURE
 
 #define SSSDBG_INVALID        -1
 #define SSSDBG_UNRESOLVED     0
-#define SSSDBG_MASK_ALL       0xFFF0   /* enable all debug levels */
+
+/* enables all debug levels;
+   0x0800 isn't used for historical reasons: 0x1FFF0 - 0x0800 = 0x1F7F0
+*/
+#define SSSDBG_MASK_ALL       0x1F7F0
 #define SSSDBG_DEFAULT        SSSDBG_FATAL_FAILURE
 
 #define SSSDBG_TIMESTAMP_UNRESOLVED   -1
-- 
2.21.1