1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5 * Author: Zach Brown <zab@zabbo.net>
6 * Author: Peter J. Braam <braam@clusterfs.com>
7 * Author: Phil Schwan <phil@clusterfs.com>
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 # define EXPORT_SYMTAB
29 #include <linux/config.h>
30 #include <linux/module.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>
39 #include <linux/uio.h>
41 #include <asm/system.h>
42 #include <asm/uaccess.h>
45 #include <linux/file.h>
46 #include <linux/stat.h>
47 #include <linux/list.h>
48 #include <asm/uaccess.h>
49 #include <asm/segment.h>
51 #include <linux/proc_fs.h>
52 #include <linux/sysctl.h>
54 # define DEBUG_SUBSYSTEM S_PORTALS
56 #include <linux/kp30.h>
57 #include <asm/div64.h>
59 static struct ctl_table_header *portals_table_header = NULL;
60 extern char debug_file_path[1024];
61 extern char debug_daemon_file_path[1024];
62 extern char portals_upcall[1024];
64 #define PSDEV_PORTALS (0x100)
65 #define PSDEV_DEBUG 1 /* control debugging */
66 #define PSDEV_SUBSYSTEM_DEBUG 2 /* control debugging */
67 #define PSDEV_PRINTK 3 /* force all errors to console */
68 #define PSDEV_CONSOLE 4 /* allow _any_ messages to console */
69 #define PSDEV_DEBUG_PATH 5 /* crashdump log location */
70 #define PSDEV_DEBUG_DUMP_PATH 6 /* crashdump tracelog location */
71 #define PSDEV_PORTALS_UPCALL 7 /* User mode upcall script */
73 #define PORTALS_PRIMARY_CTLCNT 7
74 static struct ctl_table portals_table[PORTALS_PRIMARY_CTLCNT + 1] = {
75 {PSDEV_DEBUG, "debug", &portal_debug, sizeof(int), 0644, NULL,
77 {PSDEV_SUBSYSTEM_DEBUG, "subsystem_debug", &portal_subsystem_debug,
78 sizeof(int), 0644, NULL, &proc_dointvec},
79 {PSDEV_PRINTK, "printk", &portal_printk, sizeof(int), 0644, NULL,
81 {PSDEV_CONSOLE, "console", &portal_cerror, sizeof(int), 0644, NULL,
83 {PSDEV_DEBUG_PATH, "debug_path", debug_file_path,
84 sizeof(debug_file_path), 0644, NULL, &proc_dostring, &sysctl_string},
85 {PSDEV_DEBUG_DUMP_PATH, "debug_daemon_path", debug_daemon_file_path,
86 sizeof(debug_daemon_file_path), 0644, NULL, &proc_dostring,
88 {PSDEV_PORTALS_UPCALL, "upcall", portals_upcall,
89 sizeof(portals_upcall), 0644, NULL, &proc_dostring,
94 static struct ctl_table top_table[2] = {
95 {PSDEV_PORTALS, "portals", NULL, 0, 0555, portals_table},
100 #ifdef PORTALS_PROFILING
102 * profiling stuff. we do this statically for now 'cause its simple,
103 * but we could do some tricks with elf sections to have this array
104 * automatically built.
106 #define def_prof(FOO) [PROF__##FOO] = {#FOO, 0, }
108 struct prof_ent prof_ents[] = {
109 def_prof(our_recvmsg),
110 def_prof(our_sendmsg),
111 def_prof(socknal_recv),
113 def_prof(conn_list_walk),
115 def_prof(lib_finalize),
116 def_prof(pingcli_time),
117 def_prof(gmnal_send),
118 def_prof(gmnal_recv),
121 EXPORT_SYMBOL(prof_ents);
124 * this function is as crazy as the proc filling api
127 * buffer: page allocated for us to scribble in. the
128 * data returned to the user will be taken from here.
129 * *start: address of the pointer that will tell the
130 * caller where in buffer the data the user wants is.
131 * ppos: offset in the entire /proc file that the user
133 * wanted: the amount of data the user wants.
135 * while going, 'curpos' is the offset in the entire
136 * file where we currently are. We only actually
137 * start filling buffer when we get to a place in
138 * the file that the user cares about.
140 * we take care to only sprintf when the user cares because
141 * we're holding a lock while we do this.
143 * we're smart and know that we generate fixed size lines.
144 * we only start writing to the buffer when the user cares.
145 * This is unpredictable because we don't snapshot the
146 * list between calls that are filling in a file from
147 * the list. The list could change mid read and the
148 * output will look very weird indeed. oh well.
151 static int prof_read_proc(char *buffer, char **start, off_t ppos, int wanted,
152 int *eof, void *data)
156 char *header = "Interval Cycles_per (Starts Finishes Total)\n";
157 int header_len = strlen(header);
158 char *format = "%-15s %.12Ld (%.12d %.12d %.12Ld)";
159 int line_len = (15 + 1 + 12 + 2 + 12 + 1 + 12 + 1 + 12 + 1);
163 if (ppos < header_len) {
164 int diff = MIN(header_len, wanted);
165 memcpy(buffer, header + ppos, diff);
175 for ( i = 0; i < MAX_PROFS ; i++) {
177 struct prof_ent *pe = &prof_ents[i];
178 long long cycles_per;
180 * find the part of the array that the buffer wants
182 if (ppos >= (curpos + line_len)) {
186 /* the clever caller split a line */
188 *start = buffer + (ppos - curpos);
191 if (pe->finishes == 0)
195 cycles_per = pe->total_cycles;
196 do_div (cycles_per, pe->finishes);
199 copied = sprintf(buffer + len, format, pe->str, cycles_per,
200 pe->starts, pe->finishes, pe->total_cycles);
204 /* pad to line len, -1 for \n */
205 if ((copied < line_len-1)) {
206 int diff = (line_len-1) - copied;
207 memset(buffer + len, ' ', diff);
214 /* bail if we have enough */
215 if (((buffer + len) - *start) >= wanted)
226 return MIN(((buffer + len) - *start), wanted);
230 * all kids love /proc :/
232 static unsigned char basedir[]="net/portals";
233 #endif /* PORTALS_PROFILING */
235 int insert_proc(void)
237 #if PORTALS_PROFILING
238 unsigned char dir[128];
239 struct proc_dir_entry *ent;
241 if (ARRAY_SIZE(prof_ents) != MAX_PROFS) {
242 CERROR("profiling enum and array are out of sync.\n");
247 * This is pretty lame. assuming that failure just
248 * means that they already existed.
250 strcat(dir, basedir);
251 create_proc_entry(dir, S_IFDIR, 0);
253 strcat(dir, "/cycles");
254 ent = create_proc_entry(dir, 0, 0);
256 CERROR("couldn't register %s?\n", dir);
261 ent->read_proc = prof_read_proc;
262 #endif /* PORTALS_PROFILING */
265 if (!portals_table_header)
266 portals_table_header = register_sysctl_table(top_table, 0);
272 void remove_proc(void)
274 #if PORTALS_PROFILING
275 unsigned char dir[128];
279 strcat(dir, basedir);
283 strcat(dir, "/cycles");
284 remove_proc_entry(dir,0);
287 remove_proc_entry(dir,0);
288 #endif /* PORTALS_PROFILING */
291 if (portals_table_header)
292 unregister_sysctl_table(portals_table_header);
293 portals_table_header = NULL;