Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / libcfs / libcfs / debug.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * libcfs/libcfs/debug.c
32  *
33  * Author: Phil Schwan <phil@clusterfs.com>
34  *
35  */
36
37 # define DEBUG_SUBSYSTEM S_LNET
38
39 #include <linux/module.h>
40 #include <linux/ctype.h>
41 #include <libcfs/libcfs_string.h>
42 #include <linux/kthread.h>
43 #include <linux/stacktrace.h>
44 #include <linux/utsname.h>
45 #include <linux/kallsyms.h>
46 #ifdef HAVE_PANIC_NOTIFIER_H
47 #include <linux/panic_notifier.h>
48 #endif
49 #include "tracefile.h"
50
51 static char debug_file_name[1024];
52
53 unsigned int libcfs_subsystem_debug = LIBCFS_S_DEFAULT;
54 EXPORT_SYMBOL(libcfs_subsystem_debug);
55 module_param(libcfs_subsystem_debug, int, 0644);
56 MODULE_PARM_DESC(libcfs_subsystem_debug, "Lustre kernel debug subsystem mask");
57
58 unsigned int libcfs_debug = LIBCFS_D_DEFAULT;
59 EXPORT_SYMBOL(libcfs_debug);
60 module_param(libcfs_debug, int, 0644);
61 MODULE_PARM_DESC(libcfs_debug, "Lustre kernel debug mask");
62
63 static int libcfs_param_debug_mb_set(const char *val,
64                                      cfs_kernel_param_arg_t *kp)
65 {
66         int rc;
67         unsigned int num;
68
69         rc = kstrtouint(val, 0, &num);
70         if (rc < 0)
71                 return rc;
72
73         num = cfs_trace_set_debug_mb(num);
74
75         *((unsigned int *)kp->arg) = num;
76         num = cfs_trace_get_debug_mb();
77         if (num)
78                 /* This value is more precise */
79                 *((unsigned int *)kp->arg) = num;
80
81         return 0;
82 }
83
84 /* While debug_mb setting look like unsigned int, in fact
85  * it needs quite a bunch of extra processing, so we define special
86  * debug_mb parameter type with corresponding methods to handle this case
87  */
88 static const struct kernel_param_ops param_ops_debug_mb = {
89         .set = libcfs_param_debug_mb_set,
90         .get = param_get_uint,
91 };
92
93 #define param_check_debug_mb(name, p) \
94                 __param_check(name, p, unsigned int)
95
96 static unsigned int libcfs_debug_mb;
97 #ifdef HAVE_KERNEL_PARAM_OPS
98 module_param(libcfs_debug_mb, debug_mb, 0644);
99 #else
100 module_param_call(libcfs_debug_mb, libcfs_param_debug_mb_set, param_get_uint,
101                   &param_ops_debug_mb, 0644);
102 #endif
103 MODULE_PARM_DESC(libcfs_debug_mb, "Total debug buffer size.");
104
105 unsigned int libcfs_printk = D_CANTMASK;
106 module_param(libcfs_printk, uint, 0644);
107 MODULE_PARM_DESC(libcfs_printk, "Lustre kernel debug console mask");
108
109 unsigned int libcfs_console_ratelimit = 1;
110 module_param(libcfs_console_ratelimit, uint, 0644);
111 MODULE_PARM_DESC(libcfs_console_ratelimit, "Lustre kernel debug console ratelimit (0 to disable)");
112
113 static int param_set_delay_minmax(const char *val,
114                                   cfs_kernel_param_arg_t *kp,
115                                   long min, long max)
116 {
117         long d;
118         int sec;
119         int rc;
120
121         rc = kstrtoint(val, 0, &sec);
122         if (rc)
123                 return -EINVAL;
124
125         /* The sysfs setting is in centiseconds */
126         d = cfs_time_seconds(sec) / 100;
127         if (d < min || d > max)
128                 return -EINVAL;
129
130         *((unsigned int *)kp->arg) = d;
131
132         return 0;
133 }
134
135 static int param_get_delay(char *buffer, cfs_kernel_param_arg_t *kp)
136 {
137         unsigned int d = *(unsigned int *)kp->arg;
138
139         param_get_byte(buffer, kp);
140         return sprintf(buffer, "%lu%c", jiffies_to_msecs(d * 10) / MSEC_PER_SEC,
141                        strnchr(buffer, PAGE_SIZE, '\n') ? '\n' : '\0');
142 }
143
144 unsigned int libcfs_console_max_delay;
145 unsigned int libcfs_console_min_delay;
146
147 static int param_set_console_max_delay(const char *val,
148                                        cfs_kernel_param_arg_t *kp)
149 {
150         return param_set_delay_minmax(val, kp,
151                                       libcfs_console_min_delay, INT_MAX);
152 }
153
154 static const struct kernel_param_ops param_ops_console_max_delay = {
155         .set = param_set_console_max_delay,
156         .get = param_get_delay,
157 };
158
159 #define param_check_console_max_delay(name, p) \
160                 __param_check(name, p, unsigned int)
161
162 #ifdef HAVE_KERNEL_PARAM_OPS
163 module_param(libcfs_console_max_delay, console_max_delay, 0644);
164 #else
165 module_param_call(libcfs_console_max_delay, param_set_console_max_delay,
166                   param_get_delay, &param_ops_console_max_delay, 0644);
167 #endif
168 MODULE_PARM_DESC(libcfs_console_max_delay, "Lustre kernel debug console max delay (jiffies)");
169
170 static int param_set_console_min_delay(const char *val,
171                                        cfs_kernel_param_arg_t *kp)
172 {
173         return param_set_delay_minmax(val, kp,
174                                       1, libcfs_console_max_delay);
175 }
176
177 static const struct kernel_param_ops param_ops_console_min_delay = {
178         .set = param_set_console_min_delay,
179         .get = param_get_delay,
180 };
181
182 #define param_check_console_min_delay(name, p) \
183                 __param_check(name, p, unsigned int)
184
185 #ifdef HAVE_KERNEL_PARAM_OPS
186 module_param(libcfs_console_min_delay, console_min_delay, 0644);
187 #else
188 module_param_call(libcfs_console_min_delay, param_set_console_min_delay,
189                   param_get_delay, &param_ops_console_min_delay, 0644);
190 #endif
191 MODULE_PARM_DESC(libcfs_console_min_delay, "Lustre kernel debug console min delay (jiffies)");
192
193 #ifndef HAVE_PARAM_SET_UINT_MINMAX
194 static int param_set_uint_minmax(const char *val,
195                                  cfs_kernel_param_arg_t *kp,
196                                  unsigned int min, unsigned int max)
197 {
198         unsigned int num;
199         int ret;
200
201         if (!val)
202                 return -EINVAL;
203
204         ret = kstrtouint(val, 0, &num);
205         if (ret < 0 || num < min || num > max)
206                 return -EINVAL;
207
208         *((unsigned int *)kp->arg) = num;
209         return 0;
210 }
211 #endif
212
213 static int param_set_uintpos(const char *val,
214                              cfs_kernel_param_arg_t *kp)
215 {
216         return param_set_uint_minmax(val, kp, 1, -1);
217 }
218
219 static const struct kernel_param_ops param_ops_uintpos = {
220         .set = param_set_uintpos,
221         .get = param_get_uint,
222 };
223
224 #define param_check_uintpos(name, p) \
225                 __param_check(name, p, unsigned int)
226
227 unsigned int libcfs_console_backoff = CDEBUG_DEFAULT_BACKOFF;
228 #ifdef HAVE_KERNEL_PARAM_OPS
229 module_param(libcfs_console_backoff, uintpos, 0644);
230 #else
231 module_param_call(libcfs_console_backoff, param_set_uintpos, param_get_uint,
232                   &param_ops_uintpos, 0644);
233 #endif
234 MODULE_PARM_DESC(libcfs_console_backoff, "Lustre kernel debug console backoff factor");
235
236 unsigned int libcfs_debug_binary = 1;
237
238 unsigned int libcfs_catastrophe;
239 EXPORT_SYMBOL(libcfs_catastrophe);
240
241 unsigned int libcfs_watchdog_ratelimit = 300;
242 EXPORT_SYMBOL(libcfs_watchdog_ratelimit);
243
244 unsigned int libcfs_panic_on_lbug = 1;
245 module_param(libcfs_panic_on_lbug, uint, 0644);
246 MODULE_PARM_DESC(libcfs_panic_on_lbug, "Lustre kernel panic on LBUG");
247
248 atomic64_t libcfs_kmem = ATOMIC64_INIT(0);
249 EXPORT_SYMBOL(libcfs_kmem);
250
251 static DECLARE_COMPLETION(debug_complete);
252
253 /* We need to pass a pointer here, but elsewhere this must be a const */
254 char *libcfs_debug_file_path = LIBCFS_DEBUG_FILE_PATH_DEFAULT;
255 EXPORT_SYMBOL(libcfs_debug_file_path);
256 module_param(libcfs_debug_file_path, charp, 0644);
257 MODULE_PARM_DESC(libcfs_debug_file_path,
258                  "Path for dumping debug logs, set 'NONE' to prevent log dumping");
259
260 int libcfs_panic_in_progress;
261
262 /* libcfs_debug_token2mask() expects the returned string in lower-case */
263 static const char *libcfs_debug_subsys2str(int subsys)
264 {
265         static const char *const libcfs_debug_subsystems[] =
266                 LIBCFS_DEBUG_SUBSYS_NAMES;
267
268         if (subsys >= ARRAY_SIZE(libcfs_debug_subsystems))
269                 return NULL;
270
271         return libcfs_debug_subsystems[subsys];
272 }
273
274 /* libcfs_debug_token2mask() expects the returned string in lower-case */
275 static const char *libcfs_debug_dbg2str(int debug)
276 {
277         static const char * const libcfs_debug_masks[] =
278                 LIBCFS_DEBUG_MASKS_NAMES;
279
280         if (debug >= ARRAY_SIZE(libcfs_debug_masks))
281                 return NULL;
282
283         return libcfs_debug_masks[debug];
284 }
285
286 int
287 libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys)
288 {
289         const char *(*fn)(int bit) = is_subsys ? libcfs_debug_subsys2str :
290                                                  libcfs_debug_dbg2str;
291         int len = 0;
292         const char *token;
293         int i;
294
295         if (mask == 0) {                        /* "0" */
296                 if (size > 0)
297                         str[0] = '0';
298                 len = 1;
299         } else {                                /* space-separated tokens */
300                 for (i = 0; i < 32; i++) {
301                         if ((mask & BIT(i)) == 0)
302                                 continue;
303
304                         token = fn(i);
305                         if (!token)     /* unused bit */
306                                 continue;
307
308                         if (len > 0) {          /* separator? */
309                                 if (len < size)
310                                         str[len] = ' ';
311                                 len++;
312                         }
313
314                         while (*token != 0) {
315                                 if (len < size)
316                                         str[len] = *token;
317                                 token++;
318                                 len++;
319                         }
320                 }
321         }
322
323         /* terminate 'str' */
324         if (len < size)
325                 str[len] = 0;
326         else
327                 str[size - 1] = 0;
328
329         return len;
330 }
331
332 int
333 libcfs_debug_str2mask(int *mask, const char *str, int is_subsys)
334 {
335         const char *(*fn)(int bit) = is_subsys ? libcfs_debug_subsys2str :
336                                                  libcfs_debug_dbg2str;
337         int m = 0;
338         int matched;
339         int n;
340         int t;
341
342         /* Allow a number for backwards compatibility */
343         for (n = strlen(str); n > 0; n--)
344                 if (!isspace(str[n-1]))
345                         break;
346         matched = n;
347         t = sscanf(str, "%i%n", &m, &matched);
348         if (t >= 1 && matched == n) {
349                 /* don't print warning for lctl set_param debug=0 or -1 */
350                 if (m != 0 && m != -1)
351                         CWARN("You are trying to use a numerical value for the mask - this will be deprecated in a future release.\n");
352                 *mask = m;
353                 return 0;
354         }
355
356         return cfs_str2mask(str, fn, mask, is_subsys ? 0 : D_CANTMASK, ~0,
357                             is_subsys ? LIBCFS_S_DEFAULT : LIBCFS_D_DEFAULT);
358 }
359
360 char lnet_debug_log_upcall[1024] = "/usr/lib/lustre/lnet_debug_log_upcall";
361
362 /* Upcall function once a Lustre log has been dumped.
363  *
364  * @file        path of the dumped log
365  */
366 static void libcfs_run_debug_log_upcall(char *file)
367 {
368         char *argv[3];
369         int rc;
370         static const char * const envp[] = {
371                 "HOME=/",
372                 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
373                 NULL
374         };
375
376         ENTRY;
377         argv[0] = lnet_debug_log_upcall;
378
379         LASSERTF(file, "called on a null filename\n");
380         argv[1] = file; /* only need to pass the path of the file */
381
382         argv[2] = NULL;
383
384         rc = call_usermodehelper(argv[0], argv, (char **)envp, 1);
385         if (rc < 0 && rc != -ENOENT) {
386                 CERROR("Error %d invoking LNET debug log upcall %s %s; check /sys/kernel/debug/lnet/debug_log_upcall\n",
387                        rc, argv[0], argv[1]);
388         } else {
389                 CDEBUG(D_HA, "Invoked LNET debug log upcall %s %s\n",
390                        argv[0], argv[1]);
391         }
392 }
393
394 /**
395  * Dump Lustre log to ::debug_file_path by calling tracefile_dump_all_pages()
396  */
397 static void libcfs_debug_dumplog_internal(void *arg)
398 {
399         static time64_t last_dump_time;
400         time64_t current_time;
401
402         current_time = ktime_get_real_seconds();
403
404         if (strncmp(libcfs_debug_file_path, "NONE", 4) != 0 &&
405             current_time > last_dump_time) {
406                 last_dump_time = current_time;
407                 snprintf(debug_file_name, sizeof(debug_file_name) - 1,
408                          "%s.%lld.%ld", libcfs_debug_file_path,
409                          (s64)current_time, (uintptr_t)arg);
410                 pr_alert("LustreError: dumping log to %s\n", debug_file_name);
411                 cfs_tracefile_dump_all_pages(debug_file_name);
412                 libcfs_run_debug_log_upcall(debug_file_name);
413         }
414 }
415
416 static int libcfs_debug_dumplog_thread(void *arg)
417 {
418         libcfs_debug_dumplog_internal(arg);
419         complete(&debug_complete);
420         return 0;
421 }
422
423 static DEFINE_MUTEX(libcfs_debug_dumplog_lock);
424
425 void libcfs_debug_dumplog(void)
426 {
427         struct task_struct *dumper;
428
429         ENTRY;
430
431         if (mutex_trylock(&libcfs_debug_dumplog_lock) == 0)
432                 return;
433
434         /* If a previous call was interrupted, debug_complete->done
435          * might be elevated, and so we won't actually wait here.
436          * So we reinit the completion to ensure we wait for
437          * one thread to complete, though it might not be the one
438          * we start if there are overlaping thread.
439          */
440         reinit_completion(&debug_complete);
441         dumper = kthread_run(libcfs_debug_dumplog_thread,
442                              (void *)(long)current->pid,
443                              "libcfs_debug_dumper");
444         if (IS_ERR(dumper))
445                 pr_err("LustreError: cannot start log dump thread: rc = %ld\n",
446                        PTR_ERR(dumper));
447         else
448                 wait_for_completion_interruptible(&debug_complete);
449
450         mutex_unlock(&libcfs_debug_dumplog_lock);
451 }
452 EXPORT_SYMBOL(libcfs_debug_dumplog);
453
454 void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msgdata)
455 {
456         libcfs_catastrophe = 1;
457         libcfs_debug_msg(msgdata, "LBUG\n");
458
459         if (in_interrupt()) {
460                 panic("LBUG in interrupt.\n");
461                 /* not reached */
462         }
463
464         dump_stack();
465         if (libcfs_panic_on_lbug)
466                 panic("LBUG");
467         else
468                 libcfs_debug_dumplog();
469         set_current_state(TASK_UNINTERRUPTIBLE);
470         while (1)
471                 schedule();
472 }
473 EXPORT_SYMBOL(lbug_with_loc);
474
475 #ifdef CONFIG_STACKTRACE
476
477 #ifndef HAVE_SAVE_STACK_TRACE_TSK
478 #define save_stack_trace_tsk(tsk, trace)                                       \
479 do {                                                                           \
480         if (tsk == current)                                                    \
481                 save_stack_trace(trace);                                       \
482         else                                                                   \
483                 pr_info("No stack, save_stack_trace_tsk() not exported\n");    \
484 } while (0)
485 #endif
486
487 static void cfs_print_stack_trace(unsigned long *entries, unsigned int nr)
488 {
489         unsigned int i;
490
491         /* Prefer %pB for backtraced symbolic names since it was added in:
492          * Linux v2.6.38-6557-g0f77a8d37825
493          * vsprintf: Introduce %pB format specifier
494          */
495         for (i = 0; i < nr; i++)
496                 pr_info("[<0>] %pB\n", (void *)entries[i]);
497 }
498
499 #define MAX_ST_ENTRIES  100
500 static DEFINE_SPINLOCK(st_lock);
501
502 static void libcfs_call_trace(struct task_struct *tsk)
503 {
504         static unsigned long entries[MAX_ST_ENTRIES];
505 #ifdef CONFIG_ARCH_STACKWALK
506         unsigned int nr_entries;
507
508         spin_lock(&st_lock);
509         pr_info("Pid: %d, comm: %.20s %s %s\n", tsk->pid, tsk->comm,
510                 init_utsname()->release, init_utsname()->version);
511         pr_info("Call Trace TBD:\n");
512         nr_entries = cfs_stack_trace_save_tsk(tsk, entries, MAX_ST_ENTRIES, 0);
513         cfs_print_stack_trace(entries, nr_entries);
514         spin_unlock(&st_lock);
515 #else
516         struct stack_trace trace;
517
518         trace.nr_entries = 0;
519         trace.max_entries = MAX_ST_ENTRIES;
520         trace.entries = entries;
521         trace.skip = 0;
522
523         spin_lock(&st_lock);
524         pr_info("Pid: %d, comm: %.20s %s %s\n", tsk->pid, tsk->comm,
525                 init_utsname()->release, init_utsname()->version);
526         pr_info("Call Trace:\n");
527         save_stack_trace_tsk(tsk, &trace);
528         cfs_print_stack_trace(trace.entries, trace.nr_entries);
529         spin_unlock(&st_lock);
530 #endif
531 }
532
533 #else /* !CONFIG_STACKTRACE */
534
535 #ifdef CONFIG_X86
536 #include <linux/nmi.h>
537 #include <asm/stacktrace.h>
538
539 #ifdef HAVE_STACKTRACE_OPS
540 static int print_trace_stack(void *data, char *name)
541 {
542         printk(" <%s> ", name);
543         return 0;
544 }
545
546 #ifdef STACKTRACE_OPS_ADDRESS_RETURN_INT
547 static int
548 #else
549 static void
550 #endif
551 print_trace_address(void *data, unsigned long addr, int reliable)
552 {
553         char fmt[32];
554
555         touch_nmi_watchdog();
556         sprintf(fmt, " [<%016lx>] %s%%s\n", addr, reliable ? "" : "? ");
557         __print_symbol(fmt, addr);
558 #ifdef STACKTRACE_OPS_ADDRESS_RETURN_INT
559         return 0;
560 #endif
561 }
562
563 static const struct stacktrace_ops print_trace_ops = {
564         .stack          = print_trace_stack,
565         .address        = print_trace_address,
566         .walk_stack     = print_context_stack,
567 };
568 #endif /* HAVE_STACKTRACE_OPS */
569
570 static void libcfs_call_trace(struct task_struct *tsk)
571 {
572 #ifdef HAVE_STACKTRACE_OPS
573         printk("Pid: %d, comm: %.20s\n", tsk->pid, tsk->comm);
574         printk("\nCall Trace:\n");
575         dump_trace(tsk, NULL, NULL, 0, &print_trace_ops, NULL);
576         printk("\n");
577 #else /* !HAVE_STACKTRACE_OPS */
578         if (tsk == current)
579                 dump_stack();
580         else
581                 CWARN("can't show stack: kernel doesn't export show_task\n");
582 #endif /* HAVE_STACKTRACE_OPS */
583 }
584
585 #else /* !CONFIG_X86 */
586
587 static void libcfs_call_trace(struct task_struct *tsk)
588 {
589         if (tsk == current)
590                 dump_stack();
591         else
592                 CWARN("can't show stack: kernel doesn't export show_task\n");
593 }
594
595 #endif /* CONFIG_X86 */
596
597 #endif /* CONFIG_STACKTRACE */
598
599 void libcfs_debug_dumpstack(struct task_struct *tsk)
600 {
601         libcfs_call_trace(tsk ?: current);
602 }
603 EXPORT_SYMBOL(libcfs_debug_dumpstack);
604
605 static int panic_notifier(struct notifier_block *self, unsigned long unused1,
606                           void *unused2)
607 {
608         if (libcfs_panic_in_progress)
609                 return 0;
610
611         libcfs_panic_in_progress = 1;
612         mb();
613
614 #ifdef LNET_DUMP_ON_PANIC
615         /* This is currently disabled because it spews far too much to the
616          * console on the rare cases it is ever triggered. */
617
618         if (in_interrupt()) {
619                 cfs_trace_debug_print();
620         } else {
621                 libcfs_debug_dumplog_internal((void *)(long)current->pid);
622         }
623 #endif
624         return 0;
625 }
626
627 static struct notifier_block libcfs_panic_notifier = {
628         .notifier_call          = panic_notifier,
629         .next                   = NULL,
630         .priority               = 10000,
631 };
632
633 static void libcfs_register_panic_notifier(void)
634 {
635         atomic_notifier_chain_register(&panic_notifier_list,
636                                        &libcfs_panic_notifier);
637 }
638
639 static void libcfs_unregister_panic_notifier(void)
640 {
641         atomic_notifier_chain_unregister(&panic_notifier_list,
642                                          &libcfs_panic_notifier);
643 }
644
645 static bool debug_started;
646
647 int libcfs_debug_init(unsigned long bufsize)
648 {
649         unsigned int max = libcfs_debug_mb;
650         int rc = 0;
651
652         if (debug_started)
653                 return 0;
654
655         debug_started = true;
656         if (libcfs_console_max_delay <= 0 || /* not set by user or */
657             libcfs_console_min_delay <= 0 || /* set to invalid values */
658             libcfs_console_min_delay >= libcfs_console_max_delay) {
659                 libcfs_console_max_delay = CDEBUG_DEFAULT_MAX_DELAY;
660                 libcfs_console_min_delay = CDEBUG_DEFAULT_MIN_DELAY;
661         }
662
663         /* If libcfs_debug_mb is uninitialized then just make the
664          * total buffers smp_num_cpus * TCD_MAX_PAGES
665          */
666         if (max < num_possible_cpus())
667                 max = TCD_MAX_PAGES;
668         else
669                 max <<= (20 - PAGE_SHIFT);
670
671         rc = cfs_tracefile_init(max);
672         if (rc)
673                 return rc;
674
675         libcfs_register_panic_notifier();
676         kernel_param_lock(THIS_MODULE);
677         libcfs_debug_mb = cfs_trace_get_debug_mb();
678         kernel_param_unlock(THIS_MODULE);
679         return rc;
680 }
681
682 int libcfs_debug_cleanup(void)
683 {
684         libcfs_unregister_panic_notifier();
685         kernel_param_lock(THIS_MODULE);
686         cfs_tracefile_exit();
687         kernel_param_unlock(THIS_MODULE);
688         debug_started = false;
689         return 0;
690 }
691
692 int libcfs_debug_clear_buffer(void)
693 {
694         cfs_trace_flush_pages();
695         return 0;
696 }
697
698 /* Debug markers, although printed by S_LNET should not be be marked as such. */
699 #undef DEBUG_SUBSYSTEM
700 #define DEBUG_SUBSYSTEM S_UNDEFINED
701 int libcfs_debug_mark_buffer(const char *text)
702 {
703         CDEBUG(D_TRACE,
704                "**************************************************\n");
705         LCONSOLE(D_WARNING, "DEBUG MARKER: %s\n", text);
706         CDEBUG(D_TRACE,
707                "**************************************************\n");
708
709         return 0;
710 }
711
712 #undef DEBUG_SUBSYSTEM
713 #define DEBUG_SUBSYSTEM S_LNET