netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0 of 2] implement tty driver for netconsole
@ 2008-11-27 21:11 Hollis Blanchard
  2008-11-27 21:11 ` [PATCH 1 of 2] netconsole: don't require struct console to send data Hollis Blanchard
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Hollis Blanchard @ 2008-11-27 21:11 UTC (permalink / raw)
  To: netdev; +Cc: mpm

I have a Kuro Box (a small NAS device running Linux), and it has no serial
console (nor any other console for that matter). The most convenient way to get
boot output is via the netconsole driver, which is what most Kuro owners do. (The u-boot
firmware even supports interactive netconsole allowing us to edit boot configuration.)

However, once past kernel boot, userspace currently has no way of outputting data over
netconsole. These patches enable that, which is really useful for seeing init
script output and debugging ramdisks before they've brought up sshd.

-Hollis

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

* [PATCH 1 of 2] netconsole: don't require struct console to send data
  2008-11-27 21:11 [PATCH 0 of 2] implement tty driver for netconsole Hollis Blanchard
@ 2008-11-27 21:11 ` Hollis Blanchard
  2008-11-30 17:21   ` Matt Mackall
  2008-11-27 21:11 ` [PATCH 2 of 2] netconsole: add write-only tty driver Hollis Blanchard
  2008-11-27 23:09 ` [PATCH 0 of 2] implement tty driver for netconsole Matt Mackall
  2 siblings, 1 reply; 9+ messages in thread
From: Hollis Blanchard @ 2008-11-27 21:11 UTC (permalink / raw)
  To: netdev; +Cc: mpm

This will allow callers not on the console path to use write_msg().

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -67,7 +67,7 @@ __setup("netconsole=", option_setup);
 /* Linked list of all configured targets */
 static LIST_HEAD(target_list);
 
-/* This needs to be a spinlock because write_msg() cannot sleep */
+/* This needs to be a spinlock because netconsole_write_msg() cannot sleep */
 static DEFINE_SPINLOCK(target_list_lock);
 
 /**
@@ -694,7 +694,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 netconsole_write_msg(const char *msg, unsigned int len)
 {
 	int frag, left;
 	unsigned long flags;
@@ -728,10 +728,15 @@ static void write_msg(struct console *co
 	spin_unlock_irqrestore(&target_list_lock, flags);
 }
 
+static void netconsole_console_write(struct console *con, const char *msg, unsigned int len)
+{
+	netconsole_write_msg(msg, len);
+}
+
 static struct console netconsole = {
 	.name	= "netcon",
 	.flags	= CON_ENABLED,
-	.write	= write_msg,
+	.write	= netconsole_console_write,
 };
 
 static int __init init_netconsole(void)

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

* [PATCH 2 of 2] netconsole: add write-only tty driver
  2008-11-27 21:11 [PATCH 0 of 2] implement tty driver for netconsole Hollis Blanchard
  2008-11-27 21:11 ` [PATCH 1 of 2] netconsole: don't require struct console to send data Hollis Blanchard
@ 2008-11-27 21:11 ` Hollis Blanchard
  2008-11-27 21:47   ` Evgeniy Polyakov
  2008-11-30 17:28   ` Matt Mackall
  2008-11-27 23:09 ` [PATCH 0 of 2] implement tty driver for netconsole Matt Mackall
  2 siblings, 2 replies; 9+ messages in thread
From: Hollis Blanchard @ 2008-11-27 21:11 UTC (permalink / raw)
  To: netdev; +Cc: mpm

This allows userspace to output to netconsole via the /dev/console device,
which is very useful to see initscript output, for example. There is only one
netconsole TTY device, and TTY output goes to all receivers specified for
console output.

Input via /dev/console is still not implemented, however.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -43,6 +43,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");
@@ -98,6 +99,8 @@ struct netconsole_target {
 	int			enabled;
 	struct netpoll		np;
 };
+
+static struct tty_driver *netconsole_tty_driver;
 
 #ifdef	CONFIG_NETCONSOLE_DYNAMIC
 
@@ -728,15 +731,74 @@ static void netconsole_write_msg(const c
 	spin_unlock_irqrestore(&target_list_lock, flags);
 }
 
+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)
+{
+	netconsole_write_msg(buf, count);
+	return count;
+}
+
+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,
+	.write_room = netconsole_tty_write_room,
+};
+
+static int __init netconsole_tty_init(void)
+{
+	netconsole_tty_driver = alloc_tty_driver(1);
+	if (!netconsole_tty_driver)
+		return -ENOMEM;
+
+	netconsole_tty_driver->owner = THIS_MODULE;
+	netconsole_tty_driver->driver_name = "netcon";
+	netconsole_tty_driver->name = "netcon";
+	netconsole_tty_driver->minor_start = 0;
+	netconsole_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
+	netconsole_tty_driver->init_termios = tty_std_termios;
+	netconsole_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
+	netconsole_tty_driver->init_termios.c_ispeed = 9600;
+	netconsole_tty_driver->init_termios.c_ospeed = 9600;
+	netconsole_tty_driver->flags = TTY_DRIVER_REAL_RAW;
+	tty_set_operations(netconsole_tty_driver, &netconsole_tty_ops);
+
+	if (tty_register_driver(netconsole_tty_driver))
+		printk(KERN_ERR "Couldn't register netconsole tty driver\n");
+
+	return 0;
+}
+device_initcall(netconsole_tty_init);
+
 static void netconsole_console_write(struct console *con, const char *msg, unsigned int len)
 {
 	netconsole_write_msg(msg, len);
+}
+
+static struct tty_driver *netconsole_console_device(struct console *console, int *index)
+{
+	*index = console->index;
+	return netconsole_tty_driver;
 }
 
 static struct console netconsole = {
 	.name	= "netcon",
 	.flags	= CON_ENABLED,
 	.write	= netconsole_console_write,
+	.device = netconsole_console_device,
 };
 
 static int __init init_netconsole(void)

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

* Re: [PATCH 2 of 2] netconsole: add write-only tty driver
  2008-11-27 21:11 ` [PATCH 2 of 2] netconsole: add write-only tty driver Hollis Blanchard
@ 2008-11-27 21:47   ` Evgeniy Polyakov
  2008-11-28  5:25     ` Hollis Blanchard
  2008-11-30 17:28   ` Matt Mackall
  1 sibling, 1 reply; 9+ messages in thread
From: Evgeniy Polyakov @ 2008-11-27 21:47 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: netdev, mpm

Hi.

Looks good. A short note below.

On Thu, Nov 27, 2008 at 03:11:02PM -0600, Hollis Blanchard (hollisb@us.ibm.com) wrote:
> +static int __init netconsole_tty_init(void)
> +{
> +	netconsole_tty_driver = alloc_tty_driver(1);
> +	if (!netconsole_tty_driver)
> +		return -ENOMEM;
> +
> +	netconsole_tty_driver->owner = THIS_MODULE;
> +	netconsole_tty_driver->driver_name = "netcon";
> +	netconsole_tty_driver->name = "netcon";
> +	netconsole_tty_driver->minor_start = 0;
> +	netconsole_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
> +	netconsole_tty_driver->init_termios = tty_std_termios;
> +	netconsole_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
> +	netconsole_tty_driver->init_termios.c_ispeed = 9600;
> +	netconsole_tty_driver->init_termios.c_ospeed = 9600;
> +	netconsole_tty_driver->flags = TTY_DRIVER_REAL_RAW;
> +	tty_set_operations(netconsole_tty_driver, &netconsole_tty_ops);
> +
> +	if (tty_register_driver(netconsole_tty_driver))
> +		printk(KERN_ERR "Couldn't register netconsole tty driver\n");
> +
> +	return 0;
> +}
> +device_initcall(netconsole_tty_init);

Would it be better called from init_netconsole()?

-- 
	Evgeniy Polyakov

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

* Re: [PATCH 0 of 2] implement tty driver for netconsole
  2008-11-27 21:11 [PATCH 0 of 2] implement tty driver for netconsole Hollis Blanchard
  2008-11-27 21:11 ` [PATCH 1 of 2] netconsole: don't require struct console to send data Hollis Blanchard
  2008-11-27 21:11 ` [PATCH 2 of 2] netconsole: add write-only tty driver Hollis Blanchard
@ 2008-11-27 23:09 ` Matt Mackall
  2008-11-30  5:39   ` David Miller
  2 siblings, 1 reply; 9+ messages in thread
From: Matt Mackall @ 2008-11-27 23:09 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: netdev

On Thu, 2008-11-27 at 15:11 -0600, Hollis Blanchard wrote:
> I have a Kuro Box (a small NAS device running Linux), and it has no serial
> console (nor any other console for that matter). The most convenient way to get
> boot output is via the netconsole driver, which is what most Kuro owners do. (The u-boot
> firmware even supports interactive netconsole allowing us to edit boot configuration.)
> 
> However, once past kernel boot, userspace currently has no way of outputting data over
> netconsole. These patches enable that, which is really useful for seeing init
> script output and debugging ramdisks before they've brought up sshd.

Awesome! I've been meaning to wire this up for ages. I'll try to look at
it over the weekend.

-- 
Mathematics is the supreme nostalgia of our time.


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

* Re: [PATCH 2 of 2] netconsole: add write-only tty driver
  2008-11-27 21:47   ` Evgeniy Polyakov
@ 2008-11-28  5:25     ` Hollis Blanchard
  0 siblings, 0 replies; 9+ messages in thread
From: Hollis Blanchard @ 2008-11-28  5:25 UTC (permalink / raw)
  To: Evgeniy Polyakov; +Cc: netdev, mpm

On Thursday 27 November 2008 15:47:01 Evgeniy Polyakov wrote:
> Hi.
> 
> Looks good. A short note below.
> 
> On Thu, Nov 27, 2008 at 03:11:02PM -0600, Hollis Blanchard 
(hollisb@us.ibm.com) wrote:
> > +static int __init netconsole_tty_init(void)
> > +{
> > +	netconsole_tty_driver = alloc_tty_driver(1);
> > +	if (!netconsole_tty_driver)
> > +		return -ENOMEM;
> > +
> > +	netconsole_tty_driver->owner = THIS_MODULE;
> > +	netconsole_tty_driver->driver_name = "netcon";
> > +	netconsole_tty_driver->name = "netcon";
> > +	netconsole_tty_driver->minor_start = 0;
> > +	netconsole_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
> > +	netconsole_tty_driver->init_termios = tty_std_termios;
> > +	netconsole_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | 
HUPCL;
> > +	netconsole_tty_driver->init_termios.c_ispeed = 9600;
> > +	netconsole_tty_driver->init_termios.c_ospeed = 9600;
> > +	netconsole_tty_driver->flags = TTY_DRIVER_REAL_RAW;
> > +	tty_set_operations(netconsole_tty_driver, &netconsole_tty_ops);
> > +
> > +	if (tty_register_driver(netconsole_tty_driver))
> > +		printk(KERN_ERR "Couldn't register netconsole tty driver\n");
> > +
> > +	return 0;
> > +}
> > +device_initcall(netconsole_tty_init);
> 
> Would it be better called from init_netconsole()?

Hmm, I don't remember what the ordering is here. "console_initcall", used with 
most other console-providing drivers, is done before alloc_tty_driver() can 
work. However, since init_netconsole() is a "module_initcall", I guess that 
should work. Well, it must, since init_netconsole() calls kzalloc() already...

-- 
Hollis Blanchard
IBM Linux Technology Center

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

* Re: [PATCH 0 of 2] implement tty driver for netconsole
  2008-11-27 23:09 ` [PATCH 0 of 2] implement tty driver for netconsole Matt Mackall
@ 2008-11-30  5:39   ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2008-11-30  5:39 UTC (permalink / raw)
  To: mpm; +Cc: hollisb, netdev

From: Matt Mackall <mpm@selenic.com>
Date: Thu, 27 Nov 2008 17:09:45 -0600

> On Thu, 2008-11-27 at 15:11 -0600, Hollis Blanchard wrote:
> > I have a Kuro Box (a small NAS device running Linux), and it has no serial
> > console (nor any other console for that matter). The most convenient way to get
> > boot output is via the netconsole driver, which is what most Kuro owners do. (The u-boot
> > firmware even supports interactive netconsole allowing us to edit boot configuration.)
> > 
> > However, once past kernel boot, userspace currently has no way of outputting data over
> > netconsole. These patches enable that, which is really useful for seeing init
> > script output and debugging ramdisks before they've brought up sshd.
> 
> Awesome! I've been meaning to wire this up for ages. I'll try to look at
> it over the weekend.

Matt if your review goes OK please ACK this and I'll toss these
patches into net-next-2.6

Thanks

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

* Re: [PATCH 1 of 2] netconsole: don't require struct console to send data
  2008-11-27 21:11 ` [PATCH 1 of 2] netconsole: don't require struct console to send data Hollis Blanchard
@ 2008-11-30 17:21   ` Matt Mackall
  0 siblings, 0 replies; 9+ messages in thread
From: Matt Mackall @ 2008-11-30 17:21 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: netdev

On Thu, 2008-11-27 at 15:11 -0600, Hollis Blanchard wrote:
> This will allow callers not on the console path to use write_msg().
> 
> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
> 
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -67,7 +67,7 @@ __setup("netconsole=", option_setup);
>  /* Linked list of all configured targets */
>  static LIST_HEAD(target_list);
>  
> -/* This needs to be a spinlock because write_msg() cannot sleep */
> +/* This needs to be a spinlock because netconsole_write_msg() cannot sleep */
>  static DEFINE_SPINLOCK(target_list_lock);
>  
>  /**
> @@ -694,7 +694,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 netconsole_write_msg(const char *msg, unsigned int len)
>  {
>  	int frag, left;
>  	unsigned long flags;
> @@ -728,10 +728,15 @@ static void write_msg(struct console *co
>  	spin_unlock_irqrestore(&target_list_lock, flags);
>  }
>  
> +static void netconsole_console_write(struct console *con, const char *msg, unsigned int len)
> +{
> +	netconsole_write_msg(msg, len);
> +}
> +
>  static struct console netconsole = {
>  	.name	= "netcon",
>  	.flags	= CON_ENABLED,
> -	.write	= write_msg,
> +	.write	= netconsole_console_write,
>  };

This looks fine functionally, but the name change strikes me as
gratuitous.
 
>  static int __init init_netconsole(void)
-- 
Mathematics is the supreme nostalgia of our time.


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

* Re: [PATCH 2 of 2] netconsole: add write-only tty driver
  2008-11-27 21:11 ` [PATCH 2 of 2] netconsole: add write-only tty driver Hollis Blanchard
  2008-11-27 21:47   ` Evgeniy Polyakov
@ 2008-11-30 17:28   ` Matt Mackall
  1 sibling, 0 replies; 9+ messages in thread
From: Matt Mackall @ 2008-11-30 17:28 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: netdev

On Thu, 2008-11-27 at 15:11 -0600, Hollis Blanchard wrote:
> This allows userspace to output to netconsole via the /dev/console device,
> which is very useful to see initscript output, for example. There is only one
> netconsole TTY device, and TTY output goes to all receivers specified for
> console output.
> 
> Input via /dev/console is still not implemented, however.
> 
> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
> 
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -43,6 +43,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");
> @@ -98,6 +99,8 @@ struct netconsole_target {
>  	int			enabled;
>  	struct netpoll		np;
>  };
> +
> +static struct tty_driver *netconsole_tty_driver;
>  
>  #ifdef	CONFIG_NETCONSOLE_DYNAMIC
>  
> @@ -728,15 +731,74 @@ static void netconsole_write_msg(const c
>  	spin_unlock_irqrestore(&target_list_lock, flags);
>  }
>  
> +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)
> +{
> +	netconsole_write_msg(buf, count);
> +	return count;
> +}
> +
> +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,
> +	.write_room = netconsole_tty_write_room,
> +};
> +
> +static int __init netconsole_tty_init(void)
> +{
> +	netconsole_tty_driver = alloc_tty_driver(1);
> +	if (!netconsole_tty_driver)
> +		return -ENOMEM;
> +
> +	netconsole_tty_driver->owner = THIS_MODULE;
> +	netconsole_tty_driver->driver_name = "netcon";
> +	netconsole_tty_driver->name = "netcon";
> +	netconsole_tty_driver->minor_start = 0;
> +	netconsole_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
> +	netconsole_tty_driver->init_termios = tty_std_termios;
> +	netconsole_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
> +	netconsole_tty_driver->init_termios.c_ispeed = 9600;
> +	netconsole_tty_driver->init_termios.c_ospeed = 9600;
> +	netconsole_tty_driver->flags = TTY_DRIVER_REAL_RAW;
> +	tty_set_operations(netconsole_tty_driver, &netconsole_tty_ops);
> +
> +	if (tty_register_driver(netconsole_tty_driver))
> +		printk(KERN_ERR "Couldn't register netconsole tty driver\n");
> +
> +	return 0;
> +}
> +device_initcall(netconsole_tty_init);

I agree with Evgeniy that this should be merged into the existing init
function. Otherwise there's reader ambiguity about the ordering.
Otherwise this looks good.

-- 
Mathematics is the supreme nostalgia of our time.


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

end of thread, other threads:[~2008-11-30 17:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-27 21:11 [PATCH 0 of 2] implement tty driver for netconsole Hollis Blanchard
2008-11-27 21:11 ` [PATCH 1 of 2] netconsole: don't require struct console to send data Hollis Blanchard
2008-11-30 17:21   ` Matt Mackall
2008-11-27 21:11 ` [PATCH 2 of 2] netconsole: add write-only tty driver Hollis Blanchard
2008-11-27 21:47   ` Evgeniy Polyakov
2008-11-28  5:25     ` Hollis Blanchard
2008-11-30 17:28   ` Matt Mackall
2008-11-27 23:09 ` [PATCH 0 of 2] implement tty driver for netconsole Matt Mackall
2008-11-30  5:39   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).