All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] netconsole: Add tty driver
@ 2014-04-01 21:26 Struan Bartlett
  2014-04-01 21:37 ` David Miller
  2014-04-02 12:16 ` Tetsuo Handa
  0 siblings, 2 replies; 4+ messages in thread
From: Struan Bartlett @ 2014-04-01 21:26 UTC (permalink / raw)
  To: Matt Mackall
  Cc: linux-kernel, Andreas Schwab, netdev, David S. Miller,
	Nikolay Aleksandrov, Andy Shevchenko, Greg Kroah-Hartman,
	Jiri Pirko, Joe Perches, Dan Aloni

Adds tty driver to netconsole module. When module is loaded,
creates /dev/netcon0 device and enables support for console=netcon0
kernel cmdline option, causing /dev/console output to be sent to
/dev/netcon0. This allows startup/shutdown script output from
headless platforms to be logged over (secure) network.

To: Matt Mackall <mpm@selenic.com>
Signed-off-by: Struan Bartlett <struan.bartlett@gmail.com>
---

Changes since v1:
  * Fixed whitespace mangled by broken mailer

--- a/drivers/net/netconsole.c	2014-03-31 04:40:15.000000000 +0100
+++ b/drivers/net/netconsole.c	2014-04-01 11:58:50.000000000 +0100
@@ -15,6 +15,7 @@
   *               generic card hooks
   *               works non-modular
   * 2003-09-07    rewritten with netpoll api
+ * 2014-03-31    tty driver by Struan Bartlett
   */

  /****************************************************************
@@ -47,6 +48,7 @@
  #include <linux/netpoll.h>
  #include <linux/inet.h>
  #include <linux/configfs.h>
+#include <linux/tty.h>

  MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
  MODULE_DESCRIPTION("Console driver for network interfaces");
@@ -728,7 +730,7 @@ static struct notifier_block netconsole_
  	.notifier_call  = netconsole_netdev_event,
  };

-static void write_msg(struct console *con, const char *msg, unsigned 
int len)
+static void _write_msg(const char *msg, unsigned int len)
  {
  	int frag, left;
  	unsigned long flags;
@@ -764,10 +766,63 @@ static void write_msg(struct console *co
  	spin_unlock_irqrestore(&target_list_lock, flags);
  }

+static void write_msg(struct console *con, const char *msg, unsigned 
int len)
+{
+	_write_msg(msg, len);
+}
+
+static int netconsole_tty_open(struct tty_struct *tty, struct file *filp)
+{
+	return 0;
+}
+
+static void netconsole_tty_close(struct tty_struct *tty, struct file *filp)
+{
+}
+
+static int netconsole_tty_write(struct tty_struct *tty,
+				const unsigned char *buf, int count)
+{
+	_write_msg(buf, count);
+	return count;
+}
+
+static int netconsole_tty_put_char(struct tty_struct *tty, unsigned 
char ch)
+{
+	char temp[2] = { ch, 0 };
+	_write_msg(temp, 1);
+	return 1;
+}
+
+static int netconsole_tty_write_room(struct tty_struct *tty)
+{
+	return MAX_PRINT_CHUNK;
+}
+
+static const struct tty_operations netconsole_tty_ops = {
+	.open		= netconsole_tty_open,
+	.close		= netconsole_tty_close,
+	.write		= netconsole_tty_write,
+	.put_char	= netconsole_tty_put_char,
+	.write_room	= netconsole_tty_write_room,
+};
+
+static struct tty_port netconsole_tty_port;
+static struct tty_driver *netconsole_tty_driver;
+
+static struct tty_driver *netconsole_device(struct console *co, int *index)
+{
+	if (!(co->flags & CON_ENABLED))
+		return NULL;
+	*index = co->index;
+	return netconsole_tty_driver;
+}
+
  static struct console netconsole = {
  	.name	= "netcon",
  	.flags	= CON_ENABLED,
  	.write	= write_msg,
+	.device = netconsole_device
  };

  static int __init init_netconsole(void)
@@ -802,11 +857,39 @@ static int __init init_netconsole(void)
  	if (err)
  		goto undonotifier;

+	netconsole_tty_driver = alloc_tty_driver(1);
+	if (!netconsole_tty_driver) {
+		err = -ENOMEM;
+		goto undonotifier;
+	}
+
+	tty_port_init(&netconsole_tty_port);
+
+	netconsole_tty_driver->driver_name = "netcon";
+	netconsole_tty_driver->name = "netcon";
+	netconsole_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
+	netconsole_tty_driver->subtype = SYSTEM_TYPE_TTY;
+	netconsole_tty_driver->init_termios = tty_std_termios;
+	netconsole_tty_driver->init_termios.c_iflag = 0;
+	netconsole_tty_driver->init_termios.c_oflag = 0;
+	netconsole_tty_driver->flags = TTY_DRIVER_REAL_RAW;
+
+	tty_set_operations(netconsole_tty_driver, &netconsole_tty_ops);
+	tty_port_link_device(&netconsole_tty_port, netconsole_tty_driver, 0);
+
+	err = tty_register_driver(netconsole_tty_driver);
+	if (err)
+		goto undotty;
+
  	register_console(&netconsole);
  	pr_info("network logging started\n");

  	return err;

+undotty:
+	put_tty_driver(netconsole_tty_driver);
+	tty_port_destroy(&netconsole_tty_port);
+
  undonotifier:
  	unregister_netdevice_notifier(&netconsole_netdev_notifier);

@@ -830,6 +913,10 @@ static void __exit cleanup_netconsole(vo
  {
  	struct netconsole_target *nt, *tmp;

+	tty_unregister_driver(netconsole_tty_driver);
+	put_tty_driver(netconsole_tty_driver);
+	tty_port_destroy(&netconsole_tty_port);
+
  	unregister_console(&netconsole);
  	dynamic_netconsole_exit();
  	unregister_netdevice_notifier(&netconsole_netdev_notifier);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] netconsole: Add tty driver
  2014-04-01 21:26 [PATCH v2] netconsole: Add tty driver Struan Bartlett
@ 2014-04-01 21:37 ` David Miller
  2014-04-02 12:16 ` Tetsuo Handa
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2014-04-01 21:37 UTC (permalink / raw)
  To: struan.bartlett
  Cc: mpm, linux-kernel, schwab, netdev, nikolay, andy.shevchenko,
	gregkh, jiri, joe, alonid

From: Struan Bartlett <struan.bartlett@gmail.com>
Date: Tue, 01 Apr 2014 23:26:27 +0200

> Adds tty driver to netconsole module. When module is loaded,
> creates /dev/netcon0 device and enables support for console=netcon0
> kernel cmdline option, causing /dev/console output to be sent to
> /dev/netcon0. This allows startup/shutdown script output from
> headless platforms to be logged over (secure) network.
> 
> To: Matt Mackall <mpm@selenic.com>
> Signed-off-by: Struan Bartlett <struan.bartlett@gmail.com>
> ---
> 
> Changes since v1:
>  * Fixed whitespace mangled by broken mailer

It's still not submitted cleanly, look at what it looks like
in patchwork:

http://patchwork.ozlabs.org/patch/336171/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] netconsole: Add tty driver
  2014-04-01 21:26 [PATCH v2] netconsole: Add tty driver Struan Bartlett
  2014-04-01 21:37 ` David Miller
@ 2014-04-02 12:16 ` Tetsuo Handa
  2014-04-02 22:30   ` Struan Bartlett
  1 sibling, 1 reply; 4+ messages in thread
From: Tetsuo Handa @ 2014-04-02 12:16 UTC (permalink / raw)
  To: struan.bartlett, mpm
  Cc: linux-kernel, schwab, netdev, davem, nikolay, andy.shevchenko,
	gregkh, jiri, joe, alonid

Struan Bartlett wrote:
> Adds tty driver to netconsole module. When module is loaded,
> creates /dev/netcon0 device and enables support for console=netcon0
> kernel cmdline option, causing /dev/console output to be sent to
> /dev/netcon0. This allows startup/shutdown script output from
> headless platforms to be logged over (secure) network.

Excuse me, but I think that the netconsole logging can work only during network
interfaces (e.g. eth0) are up. Did this patch description assume that the
network interfaces are up before the startup script is started and the shutdown
script is finished before the network interfaces are down?

By the way, I uploaded a logger specialized for receiving netconsole messages
to http://sourceforge.jp/projects/akari/scm/svn/tree/head/branches/udplogger/ .
The shortage of netconsole approach compared to serial console approach is that
the netconsole logging cannot work if the network interfaces are down. If we
could log kernel messages via the netconsole module while initializing kdump
kernel by adding console=netcon0 to kdump kernel's command line, we can utilize
netconsole as an alternative tool for logging kernel messages in case
initialization of kdump kernel fails.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] netconsole: Add tty driver
  2014-04-02 12:16 ` Tetsuo Handa
@ 2014-04-02 22:30   ` Struan Bartlett
  0 siblings, 0 replies; 4+ messages in thread
From: Struan Bartlett @ 2014-04-02 22:30 UTC (permalink / raw)
  To: Tetsuo Handa, mpm
  Cc: linux-kernel, schwab, netdev, davem, nikolay, andy.shevchenko,
	gregkh, jiri, joe, alonid

On 02/04/2014 14:16, Tetsuo Handa wrote:
> Struan Bartlett wrote:
>> Adds tty driver to netconsole module. When module is loaded,
>> creates /dev/netcon0 device and enables support for console=netcon0
>> kernel cmdline option, causing /dev/console output to be sent to
>> /dev/netcon0. This allows startup/shutdown script output from
>> headless platforms to be logged over (secure) network.
> 
> Excuse me, but I think that the netconsole logging can work only during network
> interfaces (e.g. eth0) are up. Did this patch description assume that the
> network interfaces are up before the startup script is started and the shutdown
> script is finished before the network interfaces are down?

Yes it did. I hope I have clarified that in the v3 patch description.
In practice, at least in a Debian environment: i) the netconsole module itself
is generally capable of raising the network interface when it is loaded by the
initramfs init script (which precedes all /etc/init.d/* scripts); ii) very
little of consequence tends to happens during shutdown after networking is
stopped; iii) equally, it is not usually problematic to disable the networking
shutdown script, since it runs on platforms about to be rebooted or powered off.
We do this by editing the Default-Stop LSB header in /etc/init.d/networking.

> By the way, I uploaded a logger specialized for receiving netconsole messages
> to http://sourceforge.jp/projects/akari/scm/svn/tree/head/branches/udplogger/ .

Thank you. I'll check it out.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-02 22:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-01 21:26 [PATCH v2] netconsole: Add tty driver Struan Bartlett
2014-04-01 21:37 ` David Miller
2014-04-02 12:16 ` Tetsuo Handa
2014-04-02 22:30   ` Struan Bartlett

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.