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) {
81 printk("%s%s: %d:%d:(%s:%d:%s()) %.*s", ptype, prefix, hdr->ph_pid,
82 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf);
86 int trace_write_daemon_file(struct file *file, const char *buffer,
87 unsigned long count, void *data)
93 name = kmalloc(count + 1, GFP_KERNEL);
97 if (copy_from_user(name, buffer, count)) {
102 /* be nice and strip out trailing '\n' */
103 for (off = count ; off > 2 && isspace(name[off - 1]); off--)
108 down_write(&tracefile_sem);
109 if (strcmp(name, "stop") == 0) {
113 } else if (strncmp(name, "size=", 5) == 0) {
114 tracefile_size = simple_strtoul(name + 5, NULL, 0);
115 if (tracefile_size < 10 || tracefile_size > 20480)
116 tracefile_size = TRACEFILE_SIZE;
118 tracefile_size <<= 20;
122 if (name[0] != '/') {
127 if (tracefile != NULL)
132 printk(KERN_INFO "Lustre: debug daemon will attempt to start writing "
133 "to %s (%lukB max)\n", tracefile, (long)(tracefile_size >> 10));
135 trace_start_thread();
137 up_write(&tracefile_sem);
143 int trace_read_daemon_file(char *page, char **start, off_t off, int count,
144 int *eof, void *data)
148 down_read(&tracefile_sem);
149 rc = snprintf(page, count, "%s", tracefile);
150 up_read(&tracefile_sem);
155 int trace_write_debug_mb(struct file *file, const char *buffer,
156 unsigned long count, void *data)
162 if (count >= sizeof(string)) {
163 printk(KERN_ERR "Lustre: value too large (length %lu bytes)\n",
168 if (copy_from_user(string, buffer, count))
171 max = simple_strtoul(string, NULL, 0);
175 if (max > (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5 || max >= 512) {
176 printk(KERN_ERR "Lustre: Refusing to set debug buffer size to "
177 "%dMB, which is more than 80%% of available RAM (%lu)\n",
178 max, (num_physpages >> (20 - 2 - PAGE_SHIFT)) / 5);
184 for (i = 0; i < NR_CPUS; i++) {
185 struct trace_cpu_data *tcd;
186 tcd = &trace_data[i].tcd;
187 tcd->tcd_max_pages = max << (20 - PAGE_SHIFT);
192 int trace_read_debug_mb(char *page, char **start, off_t off, int count,
193 int *eof, void *data)
195 struct trace_cpu_data *tcd;
199 tcd = trace_get_tcd(flags);
200 rc = snprintf(page, count, "%lu\n",
201 (tcd->tcd_max_pages >> (20 - PAGE_SHIFT)) * smp_num_cpus);
202 trace_put_tcd(tcd, flags);