Whamcloud - gitweb
file xnu_types.h was initially added on branch b_port_step.
[fs/lustre-release.git] / lustre / kernel_patches / patches / netconsole-over-netpoll.patch
1  Documentation/networking/netconsole.txt |   57 ++++++++
2  arch/i386/kernel/i386_ksyms.c           |    8 +
3  arch/i386/kernel/irq.c                  |   12 +
4  drivers/net/Kconfig                     |    7 +
5  drivers/net/Makefile                    |    1 
6  drivers/net/netconsole.c                |  217 ++++++++++++++++++++++++++++++++
7  include/asm-i386/netconsole.h           |    6 
8  net/Kconfig                             |    2 
9  net/core/dev.c                          |    3 
10  9 files changed, 311 insertions(+), 2 deletions(-)
11
12 --- linux-2.6.0-test6/arch/i386/kernel/i386_ksyms.c~netconsole-over-netpoll     2003-10-14 17:44:04.000000000 +0400
13 +++ linux-2.6.0-test6-alexey/arch/i386/kernel/i386_ksyms.c      2003-10-14 17:45:08.000000000 +0400
14 @@ -34,7 +34,7 @@
15  #include <asm/nmi.h>
16  #include <asm/edd.h>
17  #include <asm/ist.h>
18 -
19 +#include <asm/netconsole.h>
20  extern void dump_thread(struct pt_regs *, struct user *);
21  extern spinlock_t rtc_lock;
22  
23 @@ -211,6 +211,12 @@ EXPORT_SYMBOL(edd);
24  EXPORT_SYMBOL(eddnr);
25  #endif
26  
27 +#ifdef CONFIG_NETCONSOLE
28 +EXPORT_SYMBOL(netconsole_sysrq_req);
29 +EXPORT_SYMBOL(netconsole_do_sysrq);
30 +EXPORT_SYMBOL(netif_in_poll);
31 +#endif
32 +
33  #if defined(CONFIG_X86_SPEEDSTEP_SMI) || defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
34  EXPORT_SYMBOL(ist_info);
35  #endif
36 --- linux-2.6.0-test6/arch/i386/kernel/irq.c~netconsole-over-netpoll    2003-10-14 17:45:03.000000000 +0400
37 +++ linux-2.6.0-test6-alexey/arch/i386/kernel/irq.c     2003-10-14 17:45:08.000000000 +0400
38 @@ -45,6 +45,7 @@
39  #include <asm/desc.h>
40  #include <asm/irq.h>
41  #include <asm/kgdb.h>
42 +#include <asm/netconsole.h>
43  
44  /*
45   * Linux has a controller-independent x86 interrupt architecture.
46 @@ -510,6 +511,17 @@ out:
47                 BREAKPOINT;
48         }
49  #endif
50 +#ifdef CONFIG_NETCONSOLE
51 +       /*
52 +        * We need to do this after clearing out of all the interrupt
53 +        * machinery because kgdb will reenter the NIC driver and the IRQ
54 +        * system.  synchronize_irq() (at least) will deadlock.
55 +        */
56 +       if (netconsole_sysrq_req && !netif_in_poll) {
57 +               netconsole_sysrq_req = 0;
58 +               HANDLE_NETCONSOLE;
59 +       }
60 +#endif
61         return 1;
62  }
63  
64 --- /dev/null   2003-01-30 13:24:37.000000000 +0300
65 +++ linux-2.6.0-test6-alexey/Documentation/networking/netconsole.txt    2003-10-14 17:45:08.000000000 +0400
66 @@ -0,0 +1,57 @@
67 +
68 +started by Ingo Molnar <mingo@redhat.com>, 2001.09.17
69 +2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003
70 +
71 +Please send bug reports to Matt Mackall <mpm@selenic.com>
72 +
73 +This module logs kernel printk messages over UDP allowing debugging of
74 +problem where disk logging fails and serial consoles are impractical.
75 +
76 +It can be used either built-in or as a module. As a built-in,
77 +netconsole initializes immediately after NIC cards and will bring up
78 +the specified interface as soon as possible. While this doesn't allow
79 +capture of early kernel panics, it does capture most of the boot
80 +process.
81 +
82 +It takes a string configuration parameter "netconsole" in the
83 +following format:
84 +
85 + netconsole=[src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
86 +
87 +   where
88 +        src-port      source for UDP packets (defaults to 6666)
89 +        src-ip        source IP to use (interface address)
90 +        dev           network interface (eth0)
91 +        tgt-port      port for logging agent (514)
92 +        tgt-ip        IP address for logging agent
93 +        tgt-macaddr   ethernet MAC address for logging agent (broadcast)
94 +
95 +Examples:
96 +
97 + linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
98 +
99 +  or
100 +
101 + insmod netconsole netconsole=@/,@10.0.0.2/
102 +
103 +Built-in netconsole starts immediately after the TCP stack is
104 +initialized and attempts to bring up the supplied dev at the supplied
105 +address.
106 +
107 +The remote host can run either 'netcat -u -l -p <port>' or syslogd.
108 +
109 +WARNING: the default target ethernet setting uses the broadcast
110 +ethernet address to send packets, which can cause increased load on
111 +other systems on the same ethernet segment.
112 +
113 +NOTE: the network device (eth1 in the above case) can run any kind
114 +of other network traffic, netconsole is not intrusive. Netconsole
115 +might cause slight delays in other traffic if the volume of kernel
116 +messages is high, but should have no other impact.
117 +
118 +Netconsole was designed to be as instantaneous as possible, to
119 +enable the logging of even the most critical kernel bugs. It works
120 +from IRQ contexts as well, and does not enable interrupts while
121 +sending packets. Due to these unique needs, configuration can not
122 +be more automatic, and some fundamental limitations will remain:
123 +only IP networks, UDP packets and ethernet devices are supported.
124 --- linux-2.6.0-test6/drivers/net/Kconfig~netconsole-over-netpoll       2003-10-14 17:44:05.000000000 +0400
125 +++ linux-2.6.0-test6-alexey/drivers/net/Kconfig        2003-10-14 17:45:08.000000000 +0400
126 @@ -2444,6 +2444,13 @@ config SHAPER
127  config NET_POLL_CONTROLLER
128         def_bool KGDB
129  
130 +config NETCONSOLE
131 +       tristate "Network console logging support"
132 +       depends on NETDEVICES
133 +       ---help---
134 +       If you want to log kernel messages over the network, enable this.
135 +       See Documentation/networking/netconsole.txt for details.
136 +
137  source "drivers/net/wan/Kconfig"
138  
139  source "drivers/net/pcmcia/Kconfig"
140 --- linux-2.6.0-test6/drivers/net/Makefile~netconsole-over-netpoll      2003-10-14 17:45:04.000000000 +0400
141 +++ linux-2.6.0-test6-alexey/drivers/net/Makefile       2003-10-14 17:45:08.000000000 +0400
142 @@ -109,6 +109,7 @@ ifeq ($(CONFIG_SLIP_COMPRESSED),y)
143  endif
144  # Must come after all NICs it might use
145  obj-$(CONFIG_KGDB) += kgdb_eth.o
146 +obj-$(CONFIG_NETCONSOLE) += netconsole.o
147  
148  obj-$(CONFIG_DUMMY) += dummy.o
149  obj-$(CONFIG_DE600) += de600.o
150 --- /dev/null   2003-01-30 13:24:37.000000000 +0300
151 +++ linux-2.6.0-test6-alexey/drivers/net/netconsole.c   2003-10-14 17:45:56.000000000 +0400
152 @@ -0,0 +1,217 @@
153 +/*
154 + *  linux/drivers/net/netconsole.c
155 + *
156 + *  Copyright (C) 2001  Ingo Molnar <mingo@redhat.com>
157 + *
158 + *  This file contains the implementation of an IRQ-safe, crash-safe
159 + *  kernel console implementation that outputs kernel messages to the
160 + *  network.
161 + *
162 + * Modification history:
163 + *
164 + * 2001-09-17    started by Ingo Molnar.
165 + * 2003-08-11    2.6 port by Matt Mackall
166 + *               simplified options
167 + *               generic card hooks
168 + *               works non-modular
169 + * 2003-09-07    rewritten with netpoll api
170 + * 2003-09-27    updated by wangdi <wangdi@clusterfs.com>
171 + */
172 +
173 +/****************************************************************
174 + *      This program is free software; you can redistribute it and/or modify
175 + *      it under the terms of the GNU General Public License as published by
176 + *      the Free Software Foundation; either version 2, or (at your option)
177 + *      any later version.
178 + *
179 + *      This program is distributed in the hope that it will be useful,
180 + *      but WITHOUT ANY WARRANTY; without even the implied warranty of
181 + *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
182 + *      GNU General Public License for more details.
183 + *
184 + *      You should have received a copy of the GNU General Public License
185 + *      along with this program; if not, write to the Free Software
186 + *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
187 + *
188 + ****************************************************************/
189 +
190 +#include <linux/mm.h>
191 +#include <linux/tty.h>
192 +#include <linux/init.h>
193 +#include <linux/module.h>
194 +#include <linux/console.h>
195 +#include <linux/tty_driver.h>
196 +#include <linux/module.h>
197 +#include <linux/moduleparam.h>
198 +#include <linux/string.h>
199 +#include <linux/sysrq.h>
200 +#include <linux/smp.h>
201 +#include <linux/netpoll.h>
202 +#include <linux/dump.h>
203 +#include <linux/dump_netdev.h>
204 +#include <asm/unaligned.h>
205 +#include <asm/dump.h>
206 +#include <asm/netconsole.h>
207 +
208 +MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
209 +MODULE_DESCRIPTION("Console driver for network interfaces");
210 +MODULE_LICENSE("GPL");
211 +
212 +static char config[256];
213 +module_param_string(netconsole, config, 256, 0);
214 +MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]\n");
215 +
216 +static void rx_hook(struct netpoll *np, int port, char *msg, int len);
217 +
218 +static int sysrq_mode = 0;
219 +
220 +static req_t req;
221 +unsigned int netconsole_sysrq_req = 0;
222 +unsigned int netif_in_poll = 0;
223 +static unsigned int handle_sysrq_progress = 0;
224 +#define Set_Sysrq_mode()       (sysrq_mode = 1)
225 +#define Clear_Sysrq_mode()     (sysrq_mode = 0)
226 +
227 +static struct netpoll np = {
228 +       .name = "netconsole",
229 +       .dev_name = "eth0",
230 +       .rx_hook = rx_hook,
231 +       .local_port = 6666,
232 +       .remote_port = 6666,
233 +       .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
234 +};
235 +
236 +#define MAX_PRINT_CHUNK 1000
237 +#define MAX_SEND_BUFFER_LEN (MAX_PRINT_CHUNK + 200)
238 +
239 +static char send_buf[MAX_SEND_BUFFER_LEN];
240 +static char send_cache[MAX_PRINT_CHUNK];
241 +static unsigned int send_cache_pos = 0;
242 +
243 +static void send_msg_buffer(struct netpoll *np, const char *msg, int len)
244 +{
245 +       reply_t reply;
246
247 +       send_buf[0] = NETCONSOLE_VERSION;
248 +        reply.code = REPLY_LOG;
249 +        reply.nr = 0;
250 +        reply.info = 0;
251 +
252 +        put_unaligned(htonl(reply.nr), (u32 *) (send_buf + 1));
253 +        put_unaligned(htonl(reply.code), (u32 *) (send_buf + 5));
254 +        put_unaligned(htonl(reply.info), (u32 *) (send_buf+ 9));
255 +
256 +       memcpy(send_buf + 1 + sizeof(reply_t), msg, len);
257 +       netpoll_send_udp(np, send_buf, len + 1 + sizeof(reply_t));
258 +       return;
259 +}
260 +static void write_msg(struct console *con, const char *msg, unsigned int len)
261 +{
262 +       unsigned long total_len = send_cache_pos + len;
263 +       unsigned long left_len = len;
264 +       unsigned long flags;
265 +
266 +       if (!sysrq_mode)
267 +               return;
268 +       if (!np.dev)
269 +               return;
270 +       while (total_len >=  MAX_PRINT_CHUNK){
271 +               unsigned long send_len = MAX_PRINT_CHUNK - send_cache_pos; 
272 +               memcpy(send_cache + send_cache_pos, msg, send_len);
273 +               local_irq_save(flags);
274 +#if 0
275 +               for(left = send_len; left; ) {
276 +                       frag = min(left, MAX_PRINT_CHUNK);
277 +                       send_msg_buffer(&np, send_buffer, frag);
278 +                       msg += frag;
279 +                       left -= frag;
280 +               }
281 +#endif
282 +               send_msg_buffer(&np, send_cache, MAX_PRINT_CHUNK);
283 +               send_cache_pos = 0;
284 +               local_irq_restore(flags);
285 +               total_len -= MAX_PRINT_CHUNK;
286 +               left_len -= send_len; 
287 +       }
288 +       if (left_len > 0){
289 +               memcpy(send_cache + send_cache_pos, msg + (len -left_len), left_len);
290 +               send_cache_pos += left_len;
291 +       }
292 +}
293 +void netconsole_do_sysrq()
294 +{
295 +        struct pt_regs regs;
296 +       unsigned long flags;    
297 +       
298 +       handle_sysrq_progress = 1; 
299 +       Set_Sysrq_mode();
300 +       get_current_regs(&regs);
301 +       handle_sysrq((int)req.from, &regs, NULL);
302 +       
303 +       if (send_cache_pos != 0){
304 +               local_irq_save(flags);
305 +               send_msg_buffer(&np, send_cache, send_cache_pos);
306 +               send_cache_pos = 0;
307 +               local_irq_restore(flags);
308 +       } 
309 +
310 +       handle_sysrq_progress = 0;
311 +       Clear_Sysrq_mode();
312 +}
313 +static void rx_hook(struct netpoll *np, int port, char *msg, int len)
314 +{
315 +       /* add sysrq support */
316 +       req_t *__req;
317 +
318 +       if (handle_sysrq_progress)
319 +               goto out;       
320 +       __req = (req_t *)(msg);
321 +       if(len < (sizeof(req_t)))
322 +               goto out;
323 +
324 +       if ((ntohl(__req->command) != COMM_SYSRQ)) 
325 +               goto out;
326 +       /*FIXME should check magic, but did not have good ways*/
327 +
328 +       req.magic = ntohl(__req->magic);
329 +       req.command = ntohl(__req->command);
330 +       req.from = ntohl(__req->from);
331 +       req.to = ntohl(__req->to);
332 +       req.nr = ntohl(__req->nr);
333 +       netconsole_sysrq_req = 1;       
334 +out:
335 +       return ;
336 +}
337 +
338 +static struct console netconsole = {
339 +       .flags = CON_ENABLED | CON_PRINTBUFFER,
340 +       .write = write_msg
341 +};
342 +
343 +static int option_setup(char *opt)
344 +{
345 +       return netpoll_parse_options(&np, opt);
346 +}
347 +
348 +__setup("netconsole=", option_setup);
349 +
350 +static int init_netconsole(void)
351 +{
352 +       if(strlen(config) && option_setup(config))
353 +               return 1;
354 +
355 +       if(!np.remote_ip || netpoll_setup(&np))
356 +               return 1;
357 +       register_console(&netconsole);
358 +       printk(KERN_INFO "netconsole: network logging started\n");
359 +       return 0;
360 +}
361 +
362 +static void cleanup_netconsole(void)
363 +{
364 +       unregister_console(&netconsole);
365 +       netpoll_cleanup(&np);
366 +}
367 +
368 +module_init(init_netconsole);
369 +module_exit(cleanup_netconsole);
370 --- /dev/null   2003-01-30 13:24:37.000000000 +0300
371 +++ linux-2.6.0-test6-alexey/include/asm-i386/netconsole.h      2003-10-14 17:45:08.000000000 +0400
372 @@ -0,0 +1,6 @@
373 +extern unsigned int netconsole_sysrq_req;
374 +extern void netconsole_do_sysrq(void);
375 +extern unsigned int netif_in_poll;
376 +#ifndef HANDLE_NETCONSOLE
377 +#define HANDLE_NETCONSOLE netconsole_do_sysrq()
378 +#endif
379 --- linux-2.6.0-test6/net/core/dev.c~netconsole-over-netpoll    2003-10-14 17:45:03.000000000 +0400
380 +++ linux-2.6.0-test6-alexey/net/core/dev.c     2003-10-14 17:45:08.000000000 +0400
381 @@ -109,6 +109,7 @@
382  #include <linux/wireless.h>            /* Note : will define WIRELESS_EXT */
383  #include <net/iw_handler.h>
384  #endif /* CONFIG_NET_RADIO */
385 +#include <asm/netconsole.h>
386  #include <asm/current.h>
387  
388  #ifdef CONFIG_KGDB
389 @@ -1687,6 +1688,7 @@ static void net_rx_action(struct softirq
390         preempt_disable();
391         local_irq_disable();
392  
393 +       netif_in_poll = 1;
394         while (!list_empty(&queue->poll_list)) {
395                 struct net_device *dev;
396  
397 @@ -1711,6 +1713,7 @@ static void net_rx_action(struct softirq
398                         local_irq_disable();
399                 }
400         }
401 +       netif_in_poll = 0;
402  out:
403         local_irq_enable();
404         preempt_enable();
405 --- linux-2.6.0-test6/net/Kconfig~netconsole-over-netpoll       2003-10-14 17:45:03.000000000 +0400
406 +++ linux-2.6.0-test6-alexey/net/Kconfig        2003-10-14 17:45:08.000000000 +0400
407 @@ -671,6 +671,6 @@ source "net/irda/Kconfig"
408  source "net/bluetooth/Kconfig"
409  
410  config NETPOLL
411 -       def_bool KGDB
412 +       def_bool KGDB || NETCONSOLE
413  
414  endmenu
415
416 _