UML - Console subsystem tidying
PATCH 4/4 UML - Console subsystem tidying
This does a lot of cleanup on the UML console system. This patch should be entirely non-functional.
The tidying is as follows:
header cleanups - the includes should be closer to minimal and complete all printks now have a severity
lots of style fixes
fd_close is restructured a little in order to reduce the nesting some functions were calling the os_* wrappers when they can
call libc directly
port_accept had a unnecessary variable
it also tested a pid unecessarily before killing it
some functions were made static
xterm_free is gone, as it was identical to generic_free
--
arch/um/drivers/chan_kern.c | 160 ++++++++++++++++++++++---------------------- arch/um/drivers/chan_user.c | 113 ++++++++++++++++--------------- arch/um/drivers/fd.c | 74 +++++++++----------- arch/um/drivers/null.c | 28 +++---- arch/um/drivers/port_kern.c | 82 ++++++++++------------ arch/um/drivers/port_user.c | 73 +++++++++----------- arch/um/drivers/pty.c | 14 ++- arch/um/drivers/tty.c | 37 ++++++---- arch/um/drivers/xterm.c | 16 +--- 9 files changed, 297 insertions(+), 300 deletions(-)
arch/um/drivers/chan_kern.c +80 -80
@@ -1,28 +1,19 @@/* -* Copyright (C) 2000, 2001, 2002 Jeff Dike ([email protected]) +* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) * Licensed under the GPL */ -#include <linux/stddef.h> -#include <linux/kernel.h> -#include <linux/list.h> #include <linux/slab.h> #include <linux/tty.h> -#include <linux/string.h> #include <linux/tty_flip.h> -#include <asm/irq.h> #include "chan_kern.h" -#include "kern.h" -#include "irq_user.h" -#include "sigio.h" -#include "line.h" #include "os.h" #ifdef CONFIG_NOCONFIG_CHAN static void *not_configged_init (char *str,int device,const struct chan_opts *opts) { -printk ("Using a channel type which is configured out of " +printk (KERN_ERR "Using a channel type which is configured out of " "UML\n" );return NULL ; }
@@ -30,34 +21,34 @@ static void *not_configged_init(char *ststatic int not_configged_open (int input,int output,int primary,void *data,char **dev_out) { -printk ("Using a channel type which is configured out of " +printk (KERN_ERR "Using a channel type which is configured out of " "UML\n" );return -ENODEV ; }static void not_configged_close (int fd,void *data) { -printk ("Using a channel type which is configured out of " +printk (KERN_ERR "Using a channel type which is configured out of " "UML\n" ); }static int not_configged_read (int fd,char *c_out,void *data) { -printk ("Using a channel type which is configured out of " +printk (KERN_ERR "Using a channel type which is configured out of " "UML\n" );return -EIO ; }static int not_configged_write (int fd,const char *buf,int len,void *data) { -printk ("Using a channel type which is configured out of " +printk (KERN_ERR "Using a channel type which is configured out of " "UML\n" );return -EIO ; }static int not_configged_console_write (int fd,const char *buf,int len) { -printk ("Using a channel type which is configured out of " +printk (KERN_ERR "Using a channel type which is configured out of " "UML\n" );return -EIO ; }
@@ -65,14 +56,14 @@ static int not_configged_console_write(istatic int not_configged_window_size (int fd,void *data,unsigned short *rows,unsigned short *cols) { -printk ("Using a channel type which is configured out of " +printk (KERN_ERR "Using a channel type which is configured out of " "UML\n" );return -ENODEV ; }static void not_configged_free (void *data) { -printk ("Using a channel type which is configured out of " +printk (KERN_ERR "Using a channel type which is configured out of " "UML\n" ); }
@@ -91,14 +82,15 @@ static const struct chan_ops not_configgstatic void tty_receive_char (struct tty_struct *tty,char ch) { -if (tty ==NULL )return ; +if (tty ==NULL ) +return ; -if (I_IXON (tty) && !I_IXOFF (tty) && !tty->raw) { -if (ch ==STOP_CHAR (tty)){ +if (I_IXON (tty) && !I_IXOFF (tty) && !tty->raw) { +if (ch ==STOP_CHAR (tty)) {stop_tty (tty);return ; } -else if (ch ==START_CHAR (tty)){ +else if (ch ==START_CHAR (tty)) {start_tty (tty);return ; }
@@ -111,14 +103,14 @@ static int open_one_chan(struct chan *ch {int fd, err; -if (chan->opened) +if (chan->opened)return 0 ; -if (chan->ops->open ==NULL ) +if (chan->ops->open ==NULL ) fd =0 ;else fd = (*chan->ops->open)(chan->input, chan->output, chan->primary, chan->data, &chan->dev); -if (fd <0 ) +if (fd <0 )return fd; err =os_set_fd_block (fd,0 );
@@ -139,10 +131,10 @@ int open_chan(struct list_head *chans)struct chan *chan;int ret, err =0 ; -list_for_each (ele, chans){ +list_for_each (ele, chans) { chan = list_entry(ele, struct chan, list); ret =open_one_chan (chan); -if (chan->primary) +if (chan->primary) err = ret; }return err;
@@ -153,9 +145,9 @@ void chan_enable_winch(struct list_headstruct list_head *ele;struct chan *chan; -list_for_each (ele, chans){ +list_for_each (ele, chans) { chan = list_entry(ele, struct chan, list); -if (chan->primary && chan->output && chan->ops->winch){ +if (chan->primary && chan->output && chan->ops->winch) {register_winch (chan->fd, tty);return ; }
@@ -168,7 +160,7 @@ int enable_chan(struct line *line)struct chan *chan;int err; -list_for_each (ele, &line->chan_list){ +list_for_each (ele, &line->chan_list) { chan = list_entry(ele, struct chan, list); err =open_one_chan (chan);if (err) {
@@ -178,7 +170,7 @@ int enable_chan(struct line *line)continue ; } -if (chan->enabled) +if (chan->enabled)continue ; err =line_setup_irq (chan->fd, chan->input, chan->output, line, chan);
@@ -215,12 +207,12 @@ void free_irqs(void)list_splice_init (&irqs_to_free, &list);spin_unlock_irqrestore (&irqs_to_free_lock, flags); -list_for_each (ele, &list){ +list_for_each (ele, &list) { chan = list_entry(ele, struct chan, free_list); -if (chan->input) +if (chan->input)free_irq (chan->line->driver->read_irq, chan); -if (chan->output) +if (chan->output)free_irq (chan->line->driver->write_irq, chan); chan->enabled =0 ; }
@@ -230,22 +222,22 @@ static void close_one_chan(struct chan * {unsigned long flags; -if (!chan->opened) +if (!chan->opened)return ; -if (delay_free_irq){ +if (delay_free_irq) {spin_lock_irqsave (&irqs_to_free_lock, flags);list_add (&chan->free_list, &irqs_to_free);spin_unlock_irqrestore (&irqs_to_free_lock, flags); }else { -if (chan->input) +if (chan->input)free_irq (chan->line->driver->read_irq, chan); -if (chan->output) +if (chan->output)free_irq (chan->line->driver->write_irq, chan); chan->enabled =0 ; } -if (chan->ops->close !=NULL ) +if (chan->ops->close !=NULL ) (*chan->ops->close)(chan->fd, chan->data); chan->opened =0 ;
@@ -274,7 +266,7 @@ void deactivate_chan(struct list_head *clist_for_each (ele, chans) { chan = list_entry(ele, struct chan, list); -if (chan->enabled && chan->input) +if (chan->enabled && chan->input)deactivate_fd (chan->fd, irq); } }
@@ -287,7 +279,7 @@ void reactivate_chan(struct list_head *clist_for_each (ele, chans) { chan = list_entry(ele, struct chan, list); -if (chan->enabled && chan->input) +if (chan->enabled && chan->input)reactivate_fd (chan->fd, irq); } }
@@ -303,6 +295,7 @@ int write_chan(struct list_head *chans, chan = list_entry(ele, struct chan, list);if (!chan->output || (chan->ops->write ==NULL ))continue ; + n = chan->ops->write (chan->fd, buf, len, chan->data);if (chan->primary) { ret = n;
@@ -319,12 +312,14 @@ int console_write_chan(struct list_headstruct chan *chan;int n, ret =0 ; -list_for_each (ele, chans){ +list_for_each (ele, chans) { chan = list_entry(ele, struct chan, list); -if (!chan->output || (chan->ops->console_write ==NULL )) +if (!chan->output || (chan->ops->console_write ==NULL ))continue ; + n = chan->ops->console_write (chan->fd, buf, len); -if (chan->primary) ret = n; +if (chan->primary) + ret = n; }return ret; }
@@ -334,10 +329,11 @@ int console_open_chan(struct line *line,int err; err =open_chan (&line->chan_list); -if (err) +if (err)return err; -printk ("Console initialized on /dev/%s%d\n" , co->name, co->index); +printk (KERN_INFO "Console initialized on /dev/%s%d\n" , co->name, + co->index);return 0 ; }
@@ -347,10 +343,10 @@ int chan_window_size(struct list_head *cstruct list_head *ele;struct chan *chan; -list_for_each (ele, chans){ +list_for_each (ele, chans) { chan = list_entry(ele, struct chan, list); -if (chan->primary){ -if (chan->ops->window_size ==NULL ) +if (chan->primary) { +if (chan->ops->window_size ==NULL )return 0 ;return chan->ops->window_size (chan->fd, chan->data, rows_out, cols_out);
@@ -365,10 +361,11 @@ static void free_one_chan(struct chan *cclose_one_chan (chan, delay_free_irq); -if (chan->ops->free !=NULL ) +if (chan->ops->free !=NULL ) (*chan->ops->free)(chan->data); -if (chan->primary && chan->output)ignore_sigio_fd (chan->fd); +if (chan->primary && chan->output) +ignore_sigio_fd (chan->fd);kfree (chan); }
@@ -377,7 +374,7 @@ static void free_chan(struct list_head *struct list_head *ele, *next;struct chan *chan; -list_for_each_safe (ele, next, chans){ +list_for_each_safe (ele, next, chans) { chan = list_entry(ele, struct chan, list);free_one_chan (chan, delay_free_irq); }
@@ -388,14 +385,14 @@ static int one_chan_config_string(struct {int n =0 ; -if (chan ==NULL ){ +if (chan ==NULL ) {CONFIG_CHUNK (str, size, n,"none" ,1 );return n; }CONFIG_CHUNK (str, size, n, chan->ops->type,0 ); -if (chan->dev ==NULL ){ +if (chan->dev ==NULL ) {CONFIG_CHUNK (str, size, n,"" ,1 );return n; }
@@ -415,7 +412,7 @@ static int chan_pair_config_string(struc str += n; size -= n; -if (in == out){ +if (in == out) {CONFIG_CHUNK (str, size, n,"" ,1 );return n; }
@@ -435,13 +432,13 @@ int chan_config_string(struct list_headstruct list_head *ele;struct chan *chan, *in =NULL , *out =NULL ; -list_for_each (ele, chans){ +list_for_each (ele, chans) { chan = list_entry(ele, struct chan, list); -if (!chan->primary) +if (!chan->primary)continue ; -if (chan->input) +if (chan->input) in = chan; -if (chan->output) +if (chan->output) out = chan; }
@@ -500,27 +497,27 @@ static struct chan *parse_chan(struct li ops =NULL ; data =NULL ; -for (i =0 ; i <ARRAY_SIZE (chan_table); i++){ +for (i =0 ; i <ARRAY_SIZE (chan_table); i++) { entry = &chan_table[i]; -if (!strncmp (str, entry->key,strlen (entry->key))){ +if (!strncmp (str, entry->key,strlen (entry->key))) { ops = entry->ops; str +=strlen (entry->key);break ; } } -if (ops ==NULL ){ +if (ops ==NULL ) { *error_out ="No match for configured backends" ;return NULL ; } data = (*ops->init)(str, device, opts); -if (data ==NULL ){ +if (data ==NULL ) { *error_out ="Configuration failed" ;return NULL ; } chan =kmalloc (sizeof (*chan),GFP_ATOMIC ); -if (chan ==NULL ){ +if (chan ==NULL ) { *error_out ="Memory allocation failed" ;return NULL ; }
@@ -546,26 +543,26 @@ int parse_chan_pair(char *str, struct listruct chan *new, *chan;char *in, *out; -if (!list_empty (chans)){ +if (!list_empty (chans)) { chan = list_entry(chans->next, struct chan, list);free_chan (chans,0 );INIT_LIST_HEAD (chans); } out =strchr (str,',' ); -if (out !=NULL ){ +if (out !=NULL ) { in = str; *out ='\0' ; out++; new =parse_chan (line, in, device, opts, error_out); -if (new ==NULL ) +if (new ==NULL )return -1 ; new->input =1 ;list_add (&new->list, chans); new =parse_chan (line, out, device, opts, error_out); -if (new ==NULL ) +if (new ==NULL )return -1 ;list_add (&new->list, chans);
@@ -573,7 +570,7 @@ int parse_chan_pair(char *str, struct li }else { new =parse_chan (line, str, device, opts, error_out); -if (new ==NULL ) +if (new ==NULL )return -1 ;list_add (&new->list, chans);
@@ -588,9 +585,9 @@ int chan_out_fd(struct list_head *chans)struct list_head *ele;struct chan *chan; -list_for_each (ele, chans){ +list_for_each (ele, chans) { chan = list_entry(ele, struct chan, list); -if (chan->primary && chan->output) +if (chan->primary && chan->output)return chan->fd; }return -1 ;
@@ -604,23 +601,25 @@ void chan_interrupt(struct list_head *chint err;char c; -list_for_each_safe (ele, next, chans){ +list_for_each_safe (ele, next, chans) { chan = list_entry(ele, struct chan, list); -if (!chan->input || (chan->ops->read ==NULL ))continue ; +if (!chan->input || (chan->ops->read ==NULL )) +continue ;do {if (tty && !tty_buffer_request_room (tty,1 )) {schedule_delayed_work (task,1 ); goto out; } err = chan->ops->read (chan->fd, &c, chan->data); -if (err >0 ) +if (err >0 )tty_receive_char (tty, c); - }while (err >0 ); + }while (err >0 ); -if (err ==0 )reactivate_fd (chan->fd, irq); -if (err == -EIO ){ -if (chan->primary){ -if (tty !=NULL ) +if (err ==0 ) +reactivate_fd (chan->fd, irq); +if (err == -EIO ) { +if (chan->primary) { +if (tty !=NULL )tty_hangup (tty);close_chan (chans,1 );return ;
@@ -629,5 +628,6 @@ void chan_interrupt(struct list_head *ch } } out: -if (tty)tty_flip_buffer_push (tty); +if (tty) +tty_flip_buffer_push (tty); }
arch/um/drivers/fd.c +35 -39
119 lines not on this page · raw message
arch/um/drivers/null.c +11 -17
@@ -1,31 +1,36 @@/* -* Copyright (C) 2002 Jeff Dike ([email protected]) +* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) * Licensed under the GPL */ -#include <stdlib.h> +#include <stddef.h> #include <errno.h> -#include "chan_user.h" +#include <fcntl.h> #include "os.h" +#include "chan_user.h" /* This address is used only as a unique identifer */ static int null_chan;static void *null_init (char *str,int device,const struct chan_opts *opts) { -return (&null_chan); +return &null_chan; }static int null_open (int input,int output,int primary,void *d,char **dev_out) { +int fd; + *dev_out =NULL ; -return (os_open_file (DEV_NULL ,of_rdwr (OPENFLAGS ()),0 )); + + fd =open (DEV_NULL ,O_RDWR ); +return (fd <0 ) ? -errno : fd; }static int null_read (int fd,char *c_out,void *unused) { -return (-ENODEV ); +return -ENODEV ; }static void null_free (void *data)
@@ -44,14 +49,3 @@ const struct chan_ops null_ops = { .free = null_free, .winch = 0, }; - -/* -* Overrides for Emacs so that we follow Linus's tabbing style. -* Emacs will notice this stuff at the end of the file and automatically -* adjust the settings for this buffer only. This must remain at the end -* of the file. -* --------------------------------------------------------------------------- -* Local variables: -* c-file-style: "linux" -* End: -*/
arch/um/drivers/port_kern.c +39 -43
198 lines not on this page · raw message
arch/um/drivers/pty.c +10 -4
@@ -56,11 +56,11 @@ static int pts_open(int input, int outpuif (data->raw) {CATCH_EINTR (err =tcgetattr (fd, &data->tt));if (err) -return err; + goto out_close; err =raw (fd);if (err) -return err; + goto out_close; } dev =ptsname (fd);
@@ -71,6 +71,10 @@ static int pts_open(int input, int outpu (*data->announce)(dev, data->dev);return fd; + +out_close: +close (fd); +return err; }static int getmaster (char *line)
@@ -119,10 +123,12 @@ static int pty_open(int input, int outpuif (fd <0 )return fd; -if (data->raw){ +if (data->raw) { err =raw (fd); -if (err) +if (err) { +close (fd);return err; + } }if (data->announce)
arch/um/drivers/port_user.c +35 -38
170 lines not on this page · raw message
arch/um/drivers/tty.c +22 -15
@@ -1,16 +1,16 @@/* -* Copyright (C) 2001 Jeff Dike ([email protected]) +* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) * Licensed under the GPL */ -#include <stdio.h> -#include <termios.h> #include <errno.h> -#include <unistd.h> +#include <fcntl.h> +#include <termios.h> #include "chan_user.h" -#include "user.h" +#include "kern_constants.h" #include "os.h" #include "um_malloc.h" +#include "user.h" struct tty_chan {char *dev;
@@ -22,15 +22,15 @@ static void *tty_chan_init(char *str, in {struct tty_chan *data; -if (*str !=':' ){ -printk ("tty_init : channel type 'tty' must specify " +if (*str !=':' ) { +printk (UM_KERN_ERR "tty_init : channel type 'tty' must specify " "a device\n" );return NULL ; } str++; data =kmalloc (sizeof (*data),UM_GFP_KERNEL ); -if (data ==NULL ) +if (data ==NULL )return NULL ; *data = ((struct tty_chan ) { .dev = str, .raw = opts->raw });
@@ -42,19 +42,26 @@ static int tty_open(int input, int outpu char **dev_out) {struct tty_chan *data = d; -int fd, err; +int fd, err, mode =0 ; - fd =os_open_file (data->dev,of_set_rw (OPENFLAGS (), input, output),0 ); -if (fd <0 ) -return fd; +if (input && output) + mode =O_RDWR ; +else if (input) + mode =O_RDONLY ; +else if (output) + mode =O_WRONLY ; + + fd =open (data->dev, mode); +if (fd <0 ) +return -errno; -if (data->raw){ +if (data->raw) {CATCH_EINTR (err =tcgetattr (fd, &data->tt)); -if (err) +if (err)return err; err =raw (fd); -if (err) +if (err)return err; }
arch/um/drivers/xterm.c +6 -10
@@ -3,18 +3,19 @@* Licensed under the GPL */ +#include <stddef.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> -#include <string.h> #include <errno.h> +#include <string.h> #include <termios.h> #include "chan_user.h" +#include "kern_constants.h" #include "os.h" -#include "init.h" +#include "um_malloc.h" #include "user.h" #include "xterm.h" -#include "kern_constants.h" struct xterm_chan {int pid;
@@ -29,7 +30,7 @@ static void *xterm_init(char *str, int d {struct xterm_chan *data; - data =malloc (sizeof (*data)); + data =kmalloc (sizeof (*data),UM_GFP_KERNEL );if (data ==NULL )return NULL ; *data = ((struct xterm_chan) { .pid = -1,
@@ -207,11 +208,6 @@ static void xterm_close(int fd, void *d)os_close_file (fd); } -static void xterm_free (void *d) -{ -free (d); -} -const struct chan_ops xterm_ops = { .type ="xterm" , .init = xterm_init,
@@ -221,6 +217,6 @@ const struct chan_ops xterm_ops = { .write = generic_write, .console_write = generic_console_write, .window_size = generic_window_size, - .free = xterm_free, + .free = generic_free, .winch = 1, };
arch/um/drivers/chan_user.c +59 -54
216 lines not on this page · raw message
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel