12a457
From 43ffd6e0bb651ce4152e2b70faa844312ef5dba3 Mon Sep 17 00:00:00 2001
12a457
From: Raghavendra Talur <rtalur@redhat.com>
12a457
Date: Mon, 15 Feb 2016 18:16:04 +0530
12a457
Subject: [PATCH 108/139] libglusterfs: Add debug and trace logs for stack trace
12a457
12a457
        Backport of http://review.gluster.org/13448
12a457
        commit c4d67a8338b42d6485f49999f310cbb9ed5359c5
12a457
12a457
It has become very difficult to identify the xlator which returned
12a457
negative op_ret. Being able to just change the log level and
12a457
visualize the stack is helpful in such cases.
12a457
12a457
Change-Id: I6545b4802c1ab4d0d230d5e9e036afb2384882e1
12a457
BUG: 1332077
12a457
Signed-off-by: Raghavendra Talur <rtalur@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/73399
12a457
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
12a457
---
12a457
 libglusterfs/src/stack.h            |   53 ++++++++++++++++++++++++++++++++--
12a457
 xlators/cluster/stripe/src/stripe.c |    6 ++--
12a457
 2 files changed, 52 insertions(+), 7 deletions(-)
12a457
12a457
diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h
12a457
index 21f9d17..cbf7e9a 100644
12a457
--- a/libglusterfs/src/stack.h
12a457
+++ b/libglusterfs/src/stack.h
12a457
@@ -263,6 +263,11 @@ STACK_RESET (call_stack_t *stack)
12a457
                 UNLOCK(&frame->root->stack_lock);                       \
12a457
                 old_THIS = THIS;                                        \
12a457
                 THIS = obj;                                             \
12a457
+                gf_msg_trace ("stack-trace", 0,                         \
12a457
+                              "stack-address: %p, "                     \
12a457
+                              "winding from %s to %s",                  \
12a457
+                              frame->root, old_THIS->name,              \
12a457
+                              THIS->name);                              \
12a457
                 if (frame->this->ctx->measure_latency)                  \
12a457
                         gf_latency_begin (_new, fn);                    \
12a457
                 fn (_new, obj, params);                                 \
12a457
@@ -279,6 +284,11 @@ STACK_RESET (call_stack_t *stack)
12a457
                 frame->wind_to = #fn;                                   \
12a457
                 old_THIS = THIS;                                        \
12a457
                 THIS = obj;                                             \
12a457
+                gf_msg_trace ("stack-trace", 0,                         \
12a457
+                              "stack-address: %p, "                     \
12a457
+                              "winding from %s to %s",                  \
12a457
+                              frame->root, old_THIS->name,              \
12a457
+                              THIS->name);                              \
12a457
                 fn (frame, obj, params);                                \
12a457
                 THIS = old_THIS;                                        \
12a457
         } while (0)
12a457
@@ -313,6 +323,11 @@ STACK_RESET (call_stack_t *stack)
12a457
                 fn##_cbk = rfn;                                         \
12a457
                 old_THIS = THIS;                                        \
12a457
                 THIS = obj;                                             \
12a457
+                gf_msg_trace ("stack-trace", 0,                         \
12a457
+                              "stack-address: %p, "                     \
12a457
+                              "winding from %s to %s",                  \
12a457
+                              frame->root, old_THIS->name,              \
12a457
+                              THIS->name);                              \
12a457
                 if (obj->ctx->measure_latency)                          \
12a457
                         gf_latency_begin (_new, fn);                    \
12a457
                 fn (_new, obj, params);                                 \
12a457
@@ -321,7 +336,7 @@ STACK_RESET (call_stack_t *stack)
12a457
 
12a457
 
12a457
 /* return from function */
12a457
-#define STACK_UNWIND(frame, params ...)                                 \
12a457
+#define STACK_UNWIND(frame, op_ret, op_errno, params ...)               \
12a457
         do {                                                            \
12a457
                 ret_fn_t      fn = NULL;                                \
12a457
                 call_frame_t *_parent = NULL;                           \
12a457
@@ -331,6 +346,20 @@ STACK_RESET (call_stack_t *stack)
12a457
                                 LG_MSG_FRAME_ERROR, "!frame");          \
12a457
                         break;                                          \
12a457
                 }                                                       \
12a457
+                if (op_ret < 0) {                                       \
12a457
+                        gf_msg_debug ("stack-trace", op_errno,          \
12a457
+                                      "stack-address: %p, "             \
12a457
+                                      "%s returned %d error: %s",       \
12a457
+                                      frame->root, THIS->name,          \
12a457
+                                      (int32_t)op_ret,                  \
12a457
+                                      strerror(op_errno));              \
12a457
+                } else {                                                \
12a457
+                        gf_msg_trace ("stack-trace", 0,                 \
12a457
+                                      "stack-address: %p, "             \
12a457
+                                      "%s returned %d",                 \
12a457
+                                      frame->root, THIS->name,          \
12a457
+                                      (int32_t)op_ret);                 \
12a457
+                }                                                       \
12a457
                 fn = frame->ret;                                        \
12a457
                 _parent = frame->parent;                                \
12a457
                 LOCK(&frame->root->stack_lock);                         \
12a457
@@ -344,13 +373,14 @@ STACK_RESET (call_stack_t *stack)
12a457
                 frame->unwind_from = __FUNCTION__;                      \
12a457
                 if (frame->this->ctx->measure_latency)                  \
12a457
                         gf_latency_end (frame);                         \
12a457
-                fn (_parent, frame->cookie, _parent->this, params);     \
12a457
+                fn (_parent, frame->cookie, _parent->this, op_ret,      \
12a457
+                    op_errno, params);                                  \
12a457
                 THIS = old_THIS;                                        \
12a457
         } while (0)
12a457
 
12a457
 
12a457
 /* return from function in type-safe way */
12a457
-#define STACK_UNWIND_STRICT(op, frame, params ...)                      \
12a457
+#define STACK_UNWIND_STRICT(op, frame, op_ret, op_errno, params ...)    \
12a457
         do {                                                            \
12a457
                 fop_##op##_cbk_t      fn = NULL;                        \
12a457
                 call_frame_t *_parent = NULL;                           \
12a457
@@ -361,6 +391,20 @@ STACK_RESET (call_stack_t *stack)
12a457
                                 LG_MSG_FRAME_ERROR, "!frame");          \
12a457
                         break;                                          \
12a457
                 }                                                       \
12a457
+                if (op_ret < 0) {                                       \
12a457
+                        gf_msg_debug ("stack-trace", op_errno,          \
12a457
+                                      "stack-address: %p, "             \
12a457
+                                      "%s returned %d error: %s",       \
12a457
+                                      frame->root, THIS->name,          \
12a457
+                                      (int32_t)op_ret,                  \
12a457
+                                      strerror(op_errno));              \
12a457
+                } else {                                                \
12a457
+                        gf_msg_trace ("stack-trace", 0,                 \
12a457
+                                      "stack-address: %p, "             \
12a457
+                                      "%s returned %d",                 \
12a457
+                                      frame->root, THIS->name,          \
12a457
+                                      (int32_t)op_ret);                 \
12a457
+                }                                                       \
12a457
                 fn = (fop_##op##_cbk_t )frame->ret;                     \
12a457
                 _parent = frame->parent;                                \
12a457
                 LOCK(&frame->root->stack_lock);                         \
12a457
@@ -374,7 +418,8 @@ STACK_RESET (call_stack_t *stack)
12a457
                 frame->unwind_from = __FUNCTION__;                      \
12a457
                 if (frame->this->ctx->measure_latency)                  \
12a457
                         gf_latency_end (frame);                         \
12a457
-                fn (_parent, frame->cookie, _parent->this, params);     \
12a457
+                fn (_parent, frame->cookie, _parent->this, op_ret,      \
12a457
+                    op_errno, params);                                  \
12a457
                 THIS = old_THIS;                                        \
12a457
         } while (0)
12a457
 
12a457
diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c
12a457
index 7847912..287b646 100644
12a457
--- a/xlators/cluster/stripe/src/stripe.c
12a457
+++ b/xlators/cluster/stripe/src/stripe.c
12a457
@@ -4939,9 +4939,9 @@ out:
12a457
                 /* all entries are directories */
12a457
                 frame->local = NULL;
12a457
                 STRIPE_STACK_UNWIND (readdir, frame,
12a457
-                                     local ? local->op_ret : -1,
12a457
-                                     local ? local->op_errno : EINVAL,
12a457
-                                     local ? &local->entries : NULL,
12a457
+                                     (local ? local->op_ret : -1),
12a457
+                                     (local ? local->op_errno : EINVAL),
12a457
+                                     (local ? &local->entries : NULL),
12a457
                                      NULL);
12a457
                 gf_dirent_free (&local->entries);
12a457
                 stripe_local_wipe (local);
12a457
-- 
12a457
1.7.1
12a457