1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
5 * Author: Phil Schwan <phil@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 # define EXPORT_SYMTAB
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/kmod.h>
30 #include <linux/notifier.h>
31 #include <linux/kernel.h>
33 #include <linux/string.h>
34 #include <linux/stat.h>
35 #include <linux/errno.h>
36 #include <linux/smp_lock.h>
37 #include <linux/unistd.h>
38 #include <linux/interrupt.h>
39 #include <asm/system.h>
40 #include <asm/uaccess.h>
41 #include <linux/completion.h>
44 #include <linux/stat.h>
45 #include <asm/uaccess.h>
46 #include <asm/segment.h>
47 #include <linux/miscdevice.h>
49 # define DEBUG_SUBSYSTEM S_PORTALS
51 #include <linux/kp30.h>
52 #include <linux/portals_compat25.h>
54 #define DEBUG_OVERFLOW 1024
55 static char *debug_buf = NULL;
56 static unsigned long debug_size = 0;
57 static atomic_t debug_off_a = ATOMIC_INIT(0);
58 static int debug_wrapped;
59 wait_queue_head_t debug_ctlwq;
60 #define DAEMON_SND_SIZE (64 << 10)
63 * used by the daemon to keep track the offset into debug_buffer for the next
64 * write to the file. Usually, the daemon is to write out buffer
65 * from debug_daemon_next_write upto debug_off
67 * Reader - portals_debug_msg()
68 * Writer - portals_debug_daemon()
69 * portals_debug_daemon_start() during daemon init time
70 * portals_debug_daemon_continue() to reset to debug_off
71 * portals_debug_clear_buffer() reset to debug_off for clear
72 * Note that *_start(), *_continue() & *clear_buffer() should serialized;
74 static atomic_t debug_daemon_next_write;
77 * A debug_daemon can be in following states
78 * stopped - stopped state means there is no debug_daemon running.
79 * accordingly, it must be in paused state
80 * a daemon is in !stopped && !paused state after
81 * "lctl debug_daemon start" creates debug_daemon successfully
83 * Reader - portals_debug_daemon()
84 * portals_debug_set_daemon() routines
85 * Writer - portals_debug_set_daemon() routines
86 * portals_debug_daemon() on IO error
87 * paused - a debug_daemon state is changed from !paused into paused
88 * when "lctl debug_daemon paused" is issued
89 * "lctl debug_daemon continue" gets a daemon into !paused mode
90 * Reader - portals_debug_set_daemon() routines
92 * Writer - portals_debug_set_daemon() on init
93 * portals_debug_daemon()
95 * Daemon state diagram.
97 * | <-- debug_daemon start
100 * | <-- debug_daemon pause
103 * | <-- debug_daemon continue
105 * (!stopped, !paused)
106 * | <-- debug_daemon stop
109 * Overlapped - this is a state when CDEBUG is too fast for the daemon to
110 * write out the debug_bufferr. That is, debug_off is to
111 * overlap debug_daemon_next_write;
112 * Reader - portals_debug_msg()
113 * Writer - portals_debug_msg()
117 * Description on Trace Daemon Synchronization
119 * Three categories of code are synchronizing between each other
120 * 1. lctl, portals_debug_set_daemon(), the user debug control code,
121 * as well as portals_debug_clear_buffer()
122 * 2. CDEBUG, portals_debug_msg(), the debug put messages routine
123 * 3. Daemon, portals_debug_daemon(), to write out debug log file
126 * Three different controls for synchronizations
128 * 1. debug_daemon_semaphore
129 * The usage of this semaphore is to serialize multiple lctl controls
130 * in manipulating debug daemon state. The semaphore serves as the
131 * gatekeeper to allow only one user control thread, at any giving time,
132 * to access debug daemon state and keeps the other user control requests
133 * in wait state until the current control request is serviced.
135 * 2. wait_queue_head_t lctl (paired with lctl_event flag)
136 * Lctl event is the event between portals_debug_set_daemon() and
137 * portals_debug_daemon(). Lctl is an indicator for portals_debug_daemon()
138 * to flush data out to file. portals_debug_daemon() is to use lctl event
139 * as signal channel to wakeup portals_debug_set_daemon() upon flush
143 * portals_debug_daemon() uses to wake up
144 * portals_debug_set_daemon(), pause and stop, routines
146 * portals_debug_set_daemon(), stop and pause operations,
147 * wait and sleep on the event
149 * 3. wait_queue_head_t daemon (paired with daemon_event flag)
150 * This is an event channel to wakeup portals_debug_daemon. Daemon
151 * wakes up to run whenever there is an event posted. Daemon handles
152 * 2 types of operations . 1. Writes data out to debug file, 2. Flushes
153 * file and terminates base on lctl event.
155 * Daemon is normally in a sleep state.
156 * Daemon is woken up through daemon event whenever CDEBUG is
157 * putting data over any 64K boundary.
158 * File flush and termination -
159 * On portals_debug_daemon_stop/pause() operations, lctl control
160 * is to wake up daemon through daemon event.
162 * We can't use sleep_on() and wake_up() to replace daemon event because
163 * portals_debug_daemon() must catch the wakeup operation posted by
164 * portals_debug_daemon_stop/pause(). Otherwise, stop and pause may
165 * stuck in lctl wait event.
168 * a. portals_debug_daemon_pause() and portals_debug_daemon_stop()
169 * uses the event to wake up portals_debug_daemon()
170 * b. portals_debug_msg() uses the event to wake up
171 * portals_debug_daemon() whenever the data output is acrossing
172 * a 64K bytes boundary.
174 * portals_debug_daemon() wakes up upon daemon event.
176 * Sequence for portals_debug_daemon_stop() operation
178 * _Portals_debug_daemon_stop()_ _Daemon_
179 * Wait_event(daemon) or running
181 * Wakeup_event (daemon)
183 * Set force_flush flag if lctlevnt
185 * Wakeup_event (lctl)
188 * Wakeup_event (daemon)
190 * Exit daemon loop if (Stopped)
191 * Wakeup_event (lctl)
193 * Return to user application
196 * _Portals_debug_msg()_ _Daemon_
197 * Wait_event(daemon) or running
198 * If (WriteStart<64K<WriteEnd)
199 * Wakeup_event(daemon)
203 struct debug_daemon_state {
204 unsigned long overlapped;
205 unsigned long stopped;
207 unsigned long lctl_event; /* event for lctl */
208 wait_queue_head_t lctl;
209 unsigned long daemon_event; /* event for daemon */
210 wait_queue_head_t daemon;
212 static struct debug_daemon_state debug_daemon_state;
213 static DECLARE_MUTEX(debug_daemon_semaphore);
215 static loff_t daemon_file_size_limit;
216 char debug_daemon_file_path[1024] = "";
218 spinlock_t portals_debug_lock = SPIN_LOCK_UNLOCKED;
219 char debug_file_path[1024] = "/tmp/lustre-log";
220 char debug_file_name[1024];
221 int handled_panic; /* to avoid recursive calls to notifiers */
222 char portals_upcall[1024] = "/usr/lib/lustre/portals_upcall";
225 int portals_do_debug_dumplog(void *arg)
231 unsigned long debug_off;
233 kportal_daemonize("");
236 journal_info = current->journal_info;
237 current->journal_info = NULL;
238 sprintf(debug_file_name, "%s.%ld", debug_file_path, CURRENT_SECONDS);
239 file = filp_open(debug_file_name, O_CREAT|O_EXCL|O_RDWR, 0644);
241 if (!file || IS_ERR(file)) {
242 CERROR("cannot open %s for dumping: %ld\n", debug_file_name,
244 GOTO(out, PTR_ERR(file));
246 printk(KERN_ALERT "LustreError: dumping log to %s ... writing ...\n",
250 debug_off = atomic_read(&debug_off_a);
254 rc = file->f_op->write(file, debug_buf + debug_off + 1,
255 debug_size-debug_off-1, &file->f_pos);
256 rc += file->f_op->write(file, debug_buf, debug_off + 1,
259 rc = file->f_op->write(file, debug_buf, debug_off,&file->f_pos);
261 printk("LustreError: wrote %d bytes\n", rc);
264 rc = file->f_op->fsync(file, file->f_dentry, 1);
266 CERROR("sync returns %d\n", rc);
269 current->journal_info = journal_info;
270 wake_up(&debug_ctlwq);
274 int portals_debug_daemon(void *arg)
279 unsigned long force_flush = 0;
280 unsigned long size, off, flags;
283 kportal_daemonize("ldebug_daemon");
285 journal_info = current->journal_info;
286 current->journal_info = NULL;
288 file = filp_open(debug_daemon_file_path,
289 O_CREAT|O_TRUNC|O_RDWR|O_LARGEFILE, 0644);
291 if (!file || IS_ERR(file)) {
292 CERROR("cannot open %s for logging", debug_daemon_file_path);
293 GOTO(out1, PTR_ERR(file));
295 printk(KERN_INFO "daemon dumping log to %s\n", debug_daemon_file_path);
297 debug_daemon_state.overlapped = 0;
298 debug_daemon_state.stopped = 0;
300 spin_lock_irqsave(&portals_debug_lock, flags);
301 off = atomic_read(&debug_off_a) + 1;
303 off = (off >= debug_size)? 0 : off;
306 atomic_set(&debug_daemon_next_write, off);
307 atomic_set(&debug_daemon_state.paused, 0);
308 spin_unlock_irqrestore(&portals_debug_lock, flags);
313 unsigned long ending;
314 unsigned long start, tail;
317 debug_daemon_state.daemon_event = 0;
319 ending = atomic_read(&debug_off_a);
320 start = atomic_read(&debug_daemon_next_write);
322 /* check if paused is imposed by lctl ? */
323 force_flush = !debug_daemon_state.lctl_event;
325 delta = ending - start;
326 tail = debug_size - start;
327 size = (delta >= 0) ? delta : tail;
328 while (size && (force_flush || (delta < 0) ||
329 (size >= DAEMON_SND_SIZE))) {
330 if (daemon_file_size_limit) {
331 int ssize = daemon_file_size_limit - file->f_pos;
336 rc = file->f_op->write(file, debug_buf+start,
339 printk(KERN_ALERT "LustreError: Debug_daemon "
340 "write error %d\n", rc);
344 delta = ending - start;
345 tail = debug_size - start;
351 size = (tail == 0) ? ending : tail;
352 if (daemon_file_size_limit == file->f_pos) {
353 // file wrapped around
357 atomic_set(&debug_daemon_next_write, start);
359 rc = file->f_op->fsync(file, file->f_dentry, 1);
361 printk(KERN_ALERT "LustreError: Debug_daemon "
362 "sync error %d\n", rc);
365 if (debug_daemon_state.stopped)
367 debug_daemon_state.lctl_event = 1;
368 wake_up(&debug_daemon_state.lctl);
370 wait_event(debug_daemon_state.daemon,
371 debug_daemon_state.daemon_event);
374 atomic_set(&debug_daemon_state.paused, 1);
375 debug_daemon_state.stopped = 1;
378 current->journal_info = journal_info;
380 debug_daemon_state.lctl_event = 1;
381 wake_up(&debug_daemon_state.lctl);
385 void portals_debug_print(void)
387 unsigned long dumplen = 64 * 1024;
388 char *start1, *start2;
390 unsigned long debug_off = atomic_read(&debug_off_a);
392 start1 = debug_buf + debug_off - dumplen;
393 if (start1 < debug_buf) {
394 start1 += debug_size;
395 end1 = debug_buf + debug_size - 1;
397 end2 = debug_buf + debug_off;
399 end1 = debug_buf + debug_off;
400 start2 = debug_buf + debug_off;
401 end2 = debug_buf + debug_off;
404 while (start1 < end1) {
405 int count = MIN(1024, end1 - start1);
406 printk("LustreError: %*s", count, start1);
409 while (start2 < end2) {
410 int count = MIN(1024, end2 - start2);
411 printk("LustreError: %*s", count, start2);
416 void portals_debug_dumplog(void)
421 init_waitqueue_head(&debug_ctlwq);
423 rc = kernel_thread(portals_do_debug_dumplog,
424 NULL, CLONE_VM | CLONE_FS | CLONE_FILES);
426 printk(KERN_ERR "LustreError: cannot start log dump thread: "
430 sleep_on(&debug_ctlwq);
433 int portals_debug_daemon_start(char *file, unsigned int size)
437 if (!debug_daemon_state.stopped)
441 strncpy(debug_daemon_file_path, file, 1024);
443 init_waitqueue_head(&debug_daemon_state.lctl);
444 init_waitqueue_head(&debug_daemon_state.daemon);
446 daemon_file_size_limit = size << 20;
448 debug_daemon_state.lctl_event = 0;
449 rc = kernel_thread(portals_debug_daemon, NULL, 0);
451 printk(KERN_ERR "LustreError: cannot start debug daemon thread\n");
452 strncpy(debug_daemon_file_path, "\0", 1);
455 wait_event(debug_daemon_state.lctl, debug_daemon_state.lctl_event);
459 int portals_debug_daemon_pause(void)
461 if (atomic_read(&debug_daemon_state.paused))
464 atomic_set(&debug_daemon_state.paused, 1);
465 debug_daemon_state.lctl_event = 0;
466 debug_daemon_state.daemon_event = 1;
467 wake_up(&debug_daemon_state.daemon);
468 wait_event(debug_daemon_state.lctl, debug_daemon_state.lctl_event);
472 int portals_debug_daemon_continue(void)
474 if (!atomic_read(&debug_daemon_state.paused))
476 if (debug_daemon_state.stopped)
479 debug_daemon_state.overlapped = 0;
480 atomic_set(&debug_daemon_next_write, atomic_read(&debug_off_a));
481 atomic_set(&debug_daemon_state.paused, 0);
485 int portals_debug_daemon_stop(void)
487 if (debug_daemon_state.stopped)
490 if (!atomic_read(&debug_daemon_state.paused))
491 portals_debug_daemon_pause();
493 debug_daemon_state.lctl_event = 0;
494 debug_daemon_state.stopped = 1;
496 debug_daemon_state.daemon_event = 1;
497 wake_up(&debug_daemon_state.daemon);
498 wait_event(debug_daemon_state.lctl, debug_daemon_state.lctl_event);
500 debug_daemon_file_path[0] = '\0';
504 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
505 char *filename, unsigned int size)
509 down(&debug_daemon_semaphore);
511 case DEBUG_DAEMON_START:
512 if (length && (filename[length -1] != '\0')) {
513 CERROR("Invalid filename for debug_daemon\n");
517 rc = portals_debug_daemon_start(filename, size);
519 case DEBUG_DAEMON_STOP:
520 rc = portals_debug_daemon_stop();
522 case DEBUG_DAEMON_PAUSE:
523 rc = portals_debug_daemon_pause();
525 case DEBUG_DAEMON_CONTINUE:
526 rc = portals_debug_daemon_continue();
529 CERROR("unknown set_daemon cmd\n");
531 up(&debug_daemon_semaphore);
535 static int panic_dumplog(struct notifier_block *self, unsigned long unused1,
543 if (in_interrupt()) {
544 portals_debug_print();
548 while (current->lock_depth >= 0)
550 portals_debug_dumplog();
554 static struct notifier_block lustre_panic_notifier = {
555 notifier_call : panic_dumplog,
560 int portals_debug_init(unsigned long bufsize)
562 unsigned long debug_off = atomic_read(&debug_off_a);
563 if (debug_buf != NULL)
566 atomic_set(&debug_daemon_state.paused, 1);
567 debug_daemon_state.stopped = 1;
569 debug_buf = vmalloc(bufsize + DEBUG_OVERFLOW);
570 if (debug_buf == NULL)
572 memset(debug_buf, 0, debug_size);
575 //printk(KERN_INFO "Portals: allocated %lu byte debug buffer at %p.\n",
576 //bufsize, debug_buf);
577 atomic_set(&debug_off_a, debug_off);
578 notifier_chain_register(&panic_notifier_list, &lustre_panic_notifier);
579 debug_size = bufsize;
584 int portals_debug_cleanup(void)
586 notifier_chain_unregister(&panic_notifier_list, &lustre_panic_notifier);
587 if (debug_buf == NULL)
590 down(&debug_daemon_semaphore);
591 portals_debug_daemon_stop();
594 atomic_set(&debug_off_a, 0);
595 up(&debug_daemon_semaphore);
600 int portals_debug_clear_buffer(void)
605 if (debug_buf == NULL)
608 down(&debug_daemon_semaphore);
609 state = atomic_read(&debug_daemon_state.paused);
611 portals_debug_daemon_pause();
612 spin_lock_irqsave(&portals_debug_lock, flags);
613 atomic_set(&debug_off_a, 0);
615 atomic_set(&debug_daemon_next_write, 0);
616 debug_daemon_state.overlapped = 0;
617 spin_unlock_irqrestore(&portals_debug_lock, flags);
620 atomic_set(&debug_daemon_state.paused, 0);
621 up(&debug_daemon_semaphore);
626 /* Debug markers, although printed by S_PORTALS
627 * should not be be marked as such.
629 #undef DEBUG_SUBSYSTEM
630 #define DEBUG_SUBSYSTEM S_UNDEFINED
631 int portals_debug_mark_buffer(char *text)
633 if (debug_buf == NULL)
636 CDEBUG(0, "********************************************************\n");
637 CWARN("DEBUG MARKER: %s\n", text);
638 CDEBUG(0, "********************************************************\n");
642 #undef DEBUG_SUBSYSTEM
643 #define DEBUG_SUBSYSTEM S_PORTALS
645 /* this copies a snapshot of the debug buffer into an array of pages
646 * before doing the potentially blocking copy into userspace. it could
647 * be warning userspace if things wrap heavily while its off copying. */
648 __s32 portals_debug_copy_to_user(char *buf, unsigned long len)
651 unsigned long total, debug_off, i, off, copied;
655 struct list_head *pos, *n;
657 if (len < debug_size)
660 for (i = 0 ; i < debug_size; i += PAGE_SIZE) {
661 page = alloc_page(GFP_NOFS);
666 list_add(&page->list, &my_pages);
669 spin_lock_irqsave(&portals_debug_lock, flags);
670 debug_off = atomic_read(&debug_off_a);
672 /* Sigh. If the buffer is empty, then skip to the end. */
673 if (debug_off == 0 && !debug_wrapped) {
674 spin_unlock_irqrestore(&portals_debug_lock, flags);
687 list_for_each(pos, &my_pages) {
688 unsigned long to_copy;
689 page = list_entry(pos, struct page, list);
691 to_copy = min(total - off, PAGE_SIZE);
694 to_copy = min(debug_size - off, PAGE_SIZE);
697 memcpy(kmap(page), debug_buf + off, to_copy);
704 if (off >= debug_size) {
706 if (to_copy != PAGE_SIZE) {
707 to_copy = PAGE_SIZE - to_copy;
713 spin_unlock_irqrestore(&portals_debug_lock, flags);
716 list_for_each(pos, &my_pages) {
717 unsigned long to_copy;
718 page = list_entry(pos, struct page, list);
720 to_copy = min(copied - off, PAGE_SIZE);
721 rc = copy_to_user(buf + off, kmap(page), to_copy);
734 list_for_each_safe(pos, n, &my_pages) {
735 page = list_entry(pos, struct page, list);
736 list_del(&page->list);
742 /* FIXME: I'm not very smart; someone smarter should make this better. */
744 portals_debug_msg(int subsys, int mask, char *file, const char *fn,
745 const int line, unsigned long stack, char *format, ...)
753 unsigned long base_offset;
754 unsigned long debug_off;
756 if (debug_buf == NULL) {
757 printk("LustreError: portals_debug_msg: debug_buf is NULL!\n");
761 spin_lock_irqsave(&portals_debug_lock, flags);
762 debug_off = atomic_read(&debug_off_a);
763 if (!atomic_read(&debug_daemon_state.paused)) {
764 unsigned long available;
766 long v = atomic_read(&debug_daemon_next_write);
768 delta = debug_off - v;
769 available = (delta>=0) ? debug_size-delta : -delta;
770 // Check if we still have enough debug buffer for CDEBUG
771 if (available < DAEMON_SND_SIZE) {
772 /* Drop CDEBUG packets until enough debug_buffer is
774 if (debug_daemon_state.overlapped)
776 /* If this is the first time, leave a marker in the
778 debug_daemon_state.overlapped = 1;
779 format = "DEBUG MARKER: Debug buffer overlapped\n";
780 printk(KERN_ERR "LustreError: debug daemon buffer "
782 } else /* More space just became available */
783 debug_daemon_state.overlapped = 0;
786 max_nob = debug_size - debug_off + DEBUG_OVERFLOW;
788 spin_unlock_irqrestore(&portals_debug_lock, flags);
789 printk("LustreError: logic error in portals_debug_msg: "
790 "< 0 bytes to write\n");
794 /* NB since we pass a non-zero sized buffer (at least) on the first
795 * print, we can be assured that by the end of all the snprinting,
796 * we _do_ have a terminated buffer, even if our message got truncated.
799 do_gettimeofday(&tv);
801 prefix_nob = snprintf(debug_buf + debug_off, max_nob,
802 "%06x:%06x:%d:%lu.%06lu:%lu:%d:",
803 subsys, mask, smp_processor_id(),
804 tv.tv_sec, tv.tv_usec, stack, current->pid);
805 max_nob -= prefix_nob;
806 if(*(format + strlen(format) - 1) != '\n')
807 *(format + strlen(format)) = '\n';
809 #if defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20))
810 msg_nob = snprintf(debug_buf + debug_off + prefix_nob, max_nob,
812 current->thread.extern_pid, file, line, fn);
813 #elif defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
814 msg_nob = snprintf(debug_buf + debug_off + prefix_nob, max_nob,
816 current->thread.mode.tt.extern_pid, file, line, fn);
818 msg_nob = snprintf(debug_buf + debug_off + prefix_nob, max_nob,
820 current->pid, file, line, fn);
823 va_start(ap, format);
824 msg_nob += vsnprintf(debug_buf + debug_off + prefix_nob + msg_nob,
825 max_nob, format, ap);
829 /* Print to console, while msg is contiguous in debug_buf */
830 /* NB safely terminated see above */
831 if ((mask & D_EMERG) != 0)
832 printk(KERN_EMERG "LustreError: %s",
833 debug_buf + debug_off + prefix_nob);
834 else if ((mask & D_ERROR) != 0)
835 printk(KERN_ERR "LustreError: %s",
836 debug_buf + debug_off + prefix_nob);
837 else if ((mask & D_WARNING) != 0)
838 printk(KERN_WARNING "Lustre: %s",
839 debug_buf + debug_off + prefix_nob);
840 else if (portal_printk)
841 printk("<%d>Lustre: %s", portal_printk,
842 debug_buf+debug_off+prefix_nob);
843 base_offset = debug_off & 0xFFFF;
845 debug_off += prefix_nob + msg_nob;
846 if (debug_off > debug_size) {
847 memcpy(debug_buf, debug_buf + debug_size,
848 debug_off - debug_size + 1);
849 debug_off -= debug_size;
853 atomic_set(&debug_off_a, debug_off);
854 if (!atomic_read(&debug_daemon_state.paused) &&
855 ((base_offset+prefix_nob+msg_nob) >= DAEMON_SND_SIZE)) {
856 debug_daemon_state.daemon_event = 1;
857 wake_up(&debug_daemon_state.daemon);
860 spin_unlock_irqrestore(&portals_debug_lock, flags);
863 void portals_debug_set_level(unsigned int debug_level)
865 printk("Lustre: Setting portals debug level to %08x\n", debug_level);
866 portal_debug = debug_level;
869 void portals_run_upcall(char **argv)
875 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
879 argv[0] = portals_upcall;
881 while (argv[argc] != NULL)
886 rc = USERMODEHELPER(argv[0], argv, envp);
888 CERROR("Error %d invoking portals upcall %s %s%s%s%s%s%s%s%s; "
889 "check /proc/sys/portals/upcall\n",
890 rc, argv[0], argv[1],
891 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
892 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
893 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
894 argc < 6 ? "" : ",...");
896 CERROR("Invoked portals upcall %s %s%s%s%s%s%s%s%s\n",
898 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
899 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
900 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
901 argc < 6 ? "" : ",...");
905 void portals_run_lbug_upcall(char *file, const char *fn, const int line)
911 snprintf (buf, sizeof buf, "%d", line);
915 argv[3] = (char *)fn;
919 portals_run_upcall (argv);
922 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
928 sprintf(str, "%u:%d.%d.%d.%d", (__u32)(nid >> 32),
936 sprintf(str, "%u:%u", (__u32)(nid >> 32), (__u32)nid);
945 #include <linux/lustre_version.h>
946 #if (LUSTRE_KERNEL_VERSION >= 30)
947 #warning "FIXME: remove workaround when l30 is widely used"
948 char stack_backtrace[LUSTRE_TRACE_SIZE];
949 spinlock_t stack_backtrace_lock = SPIN_LOCK_UNLOCKED;
951 #if defined(__arch_um__)
953 extern int is_kernel_text_address(unsigned long addr);
955 char *portals_debug_dumpstack(void)
959 char *buf = stack_backtrace;
961 unsigned long *stack = (unsigned long *)&buf;
963 size = sprintf(pbuf, " Call Trace: ");
965 while (((long) stack & (THREAD_SIZE-1)) != 0) {
967 if (is_kernel_text_address(addr)) {
968 size = sprintf(pbuf, "[<%08lx>] ", addr);
970 if (buf + LUSTRE_TRACE_SIZE <= pbuf + 12)
978 #elif defined(__i386__)
980 extern int is_kernel_text_address(unsigned long addr);
981 extern int lookup_symbol(unsigned long address, char *buf, int buflen);
983 char *portals_debug_dumpstack(void)
985 unsigned long esp = current->thread.esp;
986 unsigned long *stack = (unsigned long *)&esp;
989 char *buf = stack_backtrace;
991 static char buffer[512];
994 /* User space on another CPU? */
995 if ((esp ^ (unsigned long)current) & (PAGE_MASK<<1)){
1000 size = sprintf(pbuf, " Call Trace: ");
1002 while (((long) stack & (THREAD_SIZE-1)) != 0) {
1004 if (is_kernel_text_address(addr)) {
1005 rc = lookup_symbol(addr, buffer, 512);
1006 if (rc == -ENOSYS) {
1007 if (buf + LUSTRE_TRACE_SIZE <= pbuf + 12)
1009 size = sprintf(pbuf, "[<%08lx>] ", addr);
1011 if (buf + LUSTRE_TRACE_SIZE
1012 /* fix length + sizeof('\0') */
1013 <= pbuf + strlen(buffer) + 28 + 1)
1015 size = sprintf(pbuf, "([<%08lx>] %s (0x%p)) ",
1016 addr, buffer, stack-1);
1025 #else /* !__arch_um__ && !__i386__ */
1027 char *portals_debug_dumpstack(void)
1029 char *buf = stack_backtrace;
1034 #endif /* __arch_um__ */
1035 EXPORT_SYMBOL(stack_backtrace_lock);
1036 EXPORT_SYMBOL(portals_debug_dumpstack);
1037 #endif /* LUSTRE_KERNEL_VERSION < 30 */
1038 #endif /* __KERNEL__ */
1040 EXPORT_SYMBOL(portals_debug_dumplog);
1041 EXPORT_SYMBOL(portals_debug_msg);
1042 EXPORT_SYMBOL(portals_debug_set_level);
1043 EXPORT_SYMBOL(portals_run_upcall);
1044 EXPORT_SYMBOL(portals_run_lbug_upcall);
1045 EXPORT_SYMBOL(portals_nid2str);