[COMMON] printk: add hooking function for exynos-snapshot
authorHosung Kim <hosung0.kim@samsung.com>
Sat, 13 Jun 2015 04:15:44 +0000 (13:15 +0900)
committerDonghyeok Choe <d7271.choe@samsung.com>
Tue, 15 May 2018 04:36:37 +0000 (13:36 +0900)
This commit adds hooking function for gathering kernel log
in exynos-snapshot.

Change-Id: I4132288aec8664861f2b51873feb52d8a7da981b
Signed-off-by: Hosung Kim <hosung0.kim@samsung.com>
kernel/printk/printk.c

index c911f8f7fa2d3218ee34249c68788fad6c52ec9f..c23ba5e402b05268750de4cba6fa0ab325d8b11e 100644 (file)
@@ -586,6 +586,43 @@ static size_t print_process(const struct printk_log *msg, char *buf)
 #endif
 module_param_named(process, printk_process, bool, S_IRUGO | S_IWUSR);
 
+#ifdef CONFIG_EXYNOS_SNAPSHOT
+static size_t hook_size;
+static char hook_text[LOG_LINE_MAX + PREFIX_MAX];
+static void (*func_hook_logbuf)(const char *buf, size_t size);
+static size_t msg_print_text(const struct printk_log *msg,
+                            bool syslog, char *buf, size_t size);
+void register_hook_logbuf(void (*func)(const char *buf, size_t size))
+{
+       unsigned long flags;
+
+       raw_spin_lock_irqsave(&logbuf_lock, flags);
+       /*
+        * In register hooking function,  we should check messages already
+        * printed on log_buf. If so, they will be copyied to backup
+        * exynos log buffer
+        * */
+       if (log_first_seq != log_next_seq) {
+               unsigned int step_seq, step_idx, start, end;
+               struct printk_log *msg;
+               start = log_first_seq;
+               end = log_next_seq;
+               step_idx = log_first_idx;
+               for (step_seq = start; step_seq < end; step_seq++) {
+                       msg = (struct printk_log *)(log_buf + step_idx);
+                       hook_size = msg_print_text(msg,
+                                       true, hook_text, LOG_LINE_MAX + PREFIX_MAX);
+                       func(hook_text, hook_size);
+                       step_idx = log_next(step_idx);
+               }
+       }
+       func_hook_logbuf = func;
+       raw_spin_unlock_irqrestore(&logbuf_lock, flags);
+}
+EXPORT_SYMBOL(register_hook_logbuf);
+#endif
+
+
 /*
  * Define how much of the log buffer we could take at maximum. The value
  * must be greater than two. Note that only half of the buffer is available
@@ -672,6 +709,13 @@ static int log_store(int facility, int level,
                msg->cpu = smp_processor_id();
                msg->in_interrupt = in_interrupt() ? 1 : 0;
        }
+#endif
+#ifdef CONFIG_EXYNOS_SNAPSHOT
+       if (func_hook_logbuf) {
+               hook_size = msg_print_text(msg,
+                               true, hook_text, LOG_LINE_MAX + PREFIX_MAX);
+               func_hook_logbuf(hook_text, hook_size);
+       }
 #endif
        /* insert message */
        log_next_idx += msg->len;