1 #define DEBUG_SUBSYSTEM S_PORTALS
2 #define LUSTRE_TRACEFILE_PRIVATE
4 #include <libcfs/libcfs.h>
5 #include <libcfs/kp30.h>
9 #define get_cpu() smp_processor_id()
10 #define put_cpu() do { } while (0)
13 extern union trace_data_union trace_data[NR_CPUS];
14 extern char *tracefile;
15 extern long long tracefile_size;
16 extern struct rw_semaphore tracefile_sem;
18 inline struct trace_cpu_data *
19 __trace_get_tcd(unsigned long *flags)
21 struct trace_cpu_data *ret;
24 local_irq_save(*flags);
25 ret = &trace_data[cpu].tcd;
31 trace_put_tcd (struct trace_cpu_data *tcd, unsigned long flags)
33 local_irq_restore(flags);
38 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
39 const int line, unsigned long stack)
45 header->ph_subsys = subsys;
46 header->ph_mask = mask;
47 header->ph_cpu_id = smp_processor_id();
48 header->ph_sec = (__u32)tv.tv_sec;
49 header->ph_usec = tv.tv_usec;
50 header->ph_stack = stack;
51 header->ph_pid = current->pid;
52 header->ph_line_num = line;
53 #if defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20))
54 header->ph_extern_pid = current->thread.extern_pid;
55 #elif defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
56 header->ph_extern_pid = current->thread.mode.tt.extern_pid;
58 header->ph_extern_pid = 0;
63 void print_to_console(struct ptldebug_header *hdr, int mask, char *buf,
64 int len, char *file, const char *fn)
66 char *prefix = NULL, *ptype = NULL;
68 if ((mask & D_EMERG) != 0) {
69 prefix = "LustreError";
71 } else if ((mask & D_ERROR) != 0) {
72 prefix = "LustreError";
74 } else if ((mask & D_WARNING) != 0) {
77 } else if (portal_printk != 0 || (mask & D_CONSOLE)) {
82 if ((mask & D_CONSOLE) != 0) {
83 printk("%s%s: %.*s", ptype, prefix, len, buf);
85 printk("%s%s: %d:%d:(%s:%d:%s()) %.*s", ptype, prefix, hdr->ph_pid,
86 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf);
91 int trace_write_daemon_file(struct file *file, const char *buffer,
92 unsigned long count, void *data)
98 name = kmalloc(count + 1, GFP_KERNEL);
102 if (copy_from_user(name, buffer, count)) {
107 /* be nice and strip out trailing '\n' */
108 for (off = count ; off > 2 && isspace(name[off - 1]); off--)
113 down_write(&tracefile_sem);
114 if (strcmp(name, "stop") == 0) {
118 } else if (strncmp(name, "size=", 5) == 0) {
119 tracefile_size = simple_strtoul(name + 5, NULL, 0);
120 if (tracefile_size < 10 || tracefile_size > 20480)
121 tracefile_size = TRACEFILE_SIZE;
123 tracefile_size <<= 20;
127 if (name[0] != '/') {
132 if (tracefile != NULL)
137 printk(KERN_INFO "Lustre: debug daemon will attempt to start writing "
138 "to %s (%lukB max)\n", tracefile, (long)(tracefile_size >> 10));
140 trace_start_thread();
142 up_write(&tracefile_sem);
148 int trace_read_daemon_file(char *page, char **start, off_t off, int count,
149 int *eof, void *data)
153 down_read(&tracefile_sem);
154 rc = snprintf(page, count, "%s", tracefile);
155 up_read(&tracefile_sem);
160 int trace_write_debug_mb(struct file *file, const char *buffer,
161 unsigned long count, void *data)
167 if (count >= sizeof(string)) {
168 printk(KERN_ERR "Lustre: value too large (length %lu bytes)\n",
173 if (copy_from_user(string, buffer, count))
176 max = simple_strtoul(string, NULL, 0);
180 if (max > (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5 || max >= 512) {
181 printk(KERN_ERR "Lustre: Refusing to set debug buffer size to "
182 "%dMB, which is more than 80%% of available RAM (%lu)\n",
183 max, (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5);
189 for (i = 0; i < NR_CPUS; i++) {
190 struct trace_cpu_data *tcd;
191 tcd = &trace_data[i].tcd;
192 tcd->tcd_max_pages = max << (20 - PAGE_SHIFT);
197 int trace_read_debug_mb(char *page, char **start, off_t off, int count,
198 int *eof, void *data)
200 struct trace_cpu_data *tcd;
204 tcd = trace_get_tcd(flags);
205 rc = snprintf(page, count, "%lu\n",
206 (tcd->tcd_max_pages >> (20 - PAGE_SHIFT)) * smp_num_cpus);
207 trace_put_tcd(tcd, flags);