UML - Return hotplug errors to host
PATCH 2/6 UML - Return hotplug errors to host
I noticed that errors happening while hotplugging devices from the host were never returned back to the mconsole client. In some cases, success was returned instead of even an information-free error.
This patch cleans that up by having the low-level configuration code pass back an error string along with an error code. At the top level, which knows whether it is early boot time or responding to an mconsole request, the string is printk'd or returned to the mconsole client.
There are also whitespace and trivial code cleanups in the surrounding code.
--
arch/um/drivers/chan_kern.c | 77 ++++++----------------- arch/um/drivers/line.c | 66 +++++++++++--------- arch/um/drivers/mconsole_kern.c | 40 ++++++++---- arch/um/drivers/net_kern.c | 97 +++++++++++++---------------- arch/um/drivers/ssl.c | 24 +++++-- arch/um/drivers/stdio_console.c | 22 ++++-- arch/um/drivers/ubd_kern.c | 132 ++++++++++++++++++++++------------------ arch/um/include/chan_kern.h | 2 arch/um/include/line.h | 8 +- arch/um/include/mconsole_kern.h | 15 ---- arch/um/kernel/tt/gdb.c | 4 - arch/um/kernel/tt/gdb_kern.c | 4 - 12 files changed, 253 insertions(+), 238 deletions(-)
arch/um/drivers/line.c +39 -27
@@ -549,14 +549,16 @@ void close_lines(struct line *lines, intclose_chan (&lines[i].chan_list,0 ); } -static void setup_one_line (struct line *lines,int n,char *init,int init_prio) +static int setup_one_line (struct line *lines,int n,char *init,int init_prio, +char **error_out) {struct line *line = &lines[n]; +int err = -EINVAL ;spin_lock (&line->count_lock);if (line->tty !=NULL ){ -printk ("line_setup - device %d is open\n" , n); + *error_out ="Device is already open" ; goto out; }
@@ -569,18 +571,22 @@ static void setup_one_line(struct line * line->valid =1 ; } } + err =0 ; out:spin_unlock (&line->count_lock); +return err; }/* Common setup code for both startup command line and mconsole initialization. * @lines contains the array (of size @num) to modify; * @init is the setup string; +* @error_out is an error string in the case of failure; */ -int line_setup (struct line *lines,unsigned int num,char *init) +int line_setup (struct line *lines,unsigned int num,char *init, +char **error_out) { -int i, n; +int i, n, err;char *end;if (*init =='=' ) {
@@ -591,52 +597,56 @@ int line_setup(struct line *lines, unsigelse { n =simple_strtoul (init, &end,0 );if (*end !='=' ){ -printk (KERN_ERR "line_setup failed to parse \"%s\"\n" , - init); -return 0 ; + *error_out ="Couldn't parse device number" ; +return -EINVAL ; } init = end; } init++;if (n >= (signed int ) num) { -printk ("line_setup - %d out of range ((0 ... %d) allowed)\n" , - n, num -1 ); -return 0 ; + *error_out ="Device number out of range" ; +return -EINVAL ; + } +else if (n >=0 ){ + err =setup_one_line (lines, n, init,INIT_ONE , error_out); +if (err) +return err; } -else if (n >=0 ) -setup_one_line (lines, n, init,INIT_ONE );else { -for (i =0 ; i < num; i++) -setup_one_line (lines, i, init,INIT_ALL ); +for (i =0 ; i < num; i++){ + err =setup_one_line (lines, i, init,INIT_ALL , + error_out); +if (err) +return err; + } }return n ==-1 ? num : n; }int line_config (struct line *lines,unsigned int num,char *str, -const struct chan_opts *opts) +const struct chan_opts *opts,char **error_out) {struct line *line;char *new;int n;if (*str =='=' ){ -printk ("line_config - can't configure all devices from " -"mconsole\n" ); -return 1 ; + *error_out ="Can't configure all devices from mconsole" ; +return -EINVAL ; } new =kstrdup (str,GFP_KERNEL );if (new ==NULL ){ -printk ("line_config - kstrdup failed\n" ); -return 1 ; + *error_out ="Failed to allocate memory" ; +return -ENOMEM ; } - n =line_setup (lines, num, new); + n =line_setup (lines, num, new, error_out);if (n <0 ) -return 1 ; +return n; line = &lines[n]; -return parse_chan_pair (line->init_str, line, n, opts); +return parse_chan_pair (line->init_str, line, n, opts, error_out); } int line_get_config(char *name, struct line *lines, unsigned int num, char *str,
@@ -685,13 +695,13 @@ int line_id(char **str, int *start_out,return n; } -int line_remove (struct line *lines,unsigned int num,int n) +int line_remove (struct line *lines,unsigned int num,int n,char **error_out) {int err;char config[sizeof ("conxxxx=none\0" )];sprintf (config,"%d=none" , n); - err =line_setup (lines, num, config); + err =line_setup (lines, num, config, error_out);if (err >=0 ) err =0 ;return err;
@@ -740,6 +750,7 @@ static LIST_HEAD(winch_handlers);void lines_init (struct line *lines,int nlines,struct chan_opts *opts) {struct line *line; +char *error;int i;for (i =0 ; i < nlines; i++){
@@ -754,8 +765,9 @@ void lines_init(struct line *lines, intif (line->init_str ==NULL )printk ("lines_init - kstrdup returned NULL\n" ); -if (parse_chan_pair (line->init_str, line, i, opts)){ -printk ("parse_chan_pair failed for device %d\n" , i); +if (parse_chan_pair (line->init_str, line, i, opts, &error)){ +printk ("parse_chan_pair failed for device %d : %s\n" , + i, error); line->valid =0 ; } }
arch/um/drivers/mconsole_kern.c +27 -13
@@ -371,14 +371,16 @@ static unsigned long long unplugged_pagestatic struct list_head unplugged_pages =LIST_HEAD_INIT (unplugged_pages);static int unplug_index =UNPLUGGED_PER_PAGE ; -static int mem_config (char *str) +static int mem_config (char *str,char **error_out) {unsigned long long diff;int err = -EINVAL , i, add;char *ret; -if (str[0 ] !='=' ) +if (str[0 ] !='=' ){ + *error_out ="Expected '=' after 'mem'" ; goto out; + } str++;if (str[0 ] =='-' )
@@ -386,12 +388,17 @@ static int mem_config(char *str)else if (str[0 ] =='+' ){ add =1 ; } -else goto out; +else { + *error_out ="Expected increment to start with '-' or '+'" ; + goto out; + } str++; diff =memparse (str, &ret); -if (*ret !='\0' ) +if (*ret !='\0' ){ + *error_out ="Failed to parse memory increment" ; goto out; + } diff /=PAGE_SIZE ;
@@ -435,11 +442,14 @@ static int mem_config(char *str) unplugged =list_entry (entry, struct unplugged_pages, list); - unplugged->pages[unplug_index++] = addr; err =os_drop_memory (addr,PAGE_SIZE ); -if (err) +if (err){printk ("Failed to release memory - " "errno = %d\n" , err); + *error_out ="Failed to release memory" ; + goto out; + } + unplugged->pages[unplug_index++] = addr; } unplugged_pages_count++;
@@ -470,8 +480,9 @@ static int mem_id(char **str, int *startreturn 0 ; } -static int mem_remove (int n) +static int mem_remove (int n,char **error_out) { + *error_out ="Memory doesn't support the remove operation" ;return -EBUSY ; }
@@ -542,7 +553,7 @@ static void mconsole_get_config(int (*gevoid mconsole_config (struct mc_request *req) {struct mc_device *dev; -char *ptr = req->request.data, *name; +char *ptr = req->request.data, *name, *error_string ="" ;int err; ptr +=strlen ("config" );
@@ -559,8 +570,8 @@ void mconsole_config(struct mc_request * ptr++;if (*ptr =='=' ){ - err = (*dev->config)(name); -mconsole_reply (req,"" , err,0 ); + err = (*dev->config)(name, &error_string); +mconsole_reply (req, error_string, err,0 ); }else mconsole_get_config (dev->get_config, req, name); }
@@ -595,13 +606,16 @@ void mconsole_remove(struct mc_request * goto out; } - err = (*dev->remove)(n); + err_msg =NULL ; + err = (*dev->remove)(n, &err_msg);switch (err){case -ENODEV : - err_msg ="Device doesn't exist" ; +if (err_msg ==NULL ) + err_msg ="Device doesn't exist" ;break ;case -EBUSY : - err_msg ="Device is currently open" ; +if (err_msg ==NULL ) + err_msg ="Device is currently open" ;break ;default :break ;
arch/um/drivers/net_kern.c +46 -51
220 lines not on this page · raw message
arch/um/drivers/ubd_kern.c +74 -58
266 lines not on this page · raw message
arch/um/drivers/chan_kern.c +23 -54
169 lines not on this page · raw message
arch/um/drivers/ssl.c +17 -7
@@ -46,9 +46,9 @@ static struct chan_opts opts = { .in_kernel = 1, }; -static int ssl_config (char *str); +static int ssl_config (char *str,char **error_out);static int ssl_get_config (char *dev,char *str,int size,char **error_out); -static int ssl_remove (int n); +static int ssl_remove (int n,char **error_out);static struct line_driver driver = { .name ="UML serial line" ,
@@ -80,9 +80,10 @@ static struct line serial_lines[NR_PORTSstatic struct lines lines =LINES_INIT (NR_PORTS ); -static int ssl_config (char *str) +static int ssl_config (char *str,char **error_out) { -return line_config (serial_lines,ARRAY_SIZE (serial_lines), str, &opts); +return line_config (serial_lines,ARRAY_SIZE (serial_lines), str, &opts, + error_out); }static int ssl_get_config (char *dev,char *str,int size,char **error_out)
@@ -91,9 +92,10 @@ static int ssl_get_config(char *dev, cha size, error_out); } -static int ssl_remove (int n) +static int ssl_remove (int n,char **error_out) { -return line_remove (serial_lines,ARRAY_SIZE (serial_lines), n); +return line_remove (serial_lines,ARRAY_SIZE (serial_lines), n, + error_out); }static int ssl_open (struct tty_struct *tty,struct file *filp)
@@ -212,7 +214,15 @@ __uml_exitcall(ssl_exit);static int ssl_chan_setup (char *str) { -return line_setup (serial_lines,ARRAY_SIZE (serial_lines), str); +char *error; +int ret; + + ret =line_setup (serial_lines,ARRAY_SIZE (serial_lines), str, &error); +if (ret <0 ) +printk (KERN_ERR "Failed to set up serial line with " +"configuration string \"%s\" : %s\n" , str, error); + +return 1 ; }__setup ("ssl" , ssl_chan_setup);
arch/um/drivers/stdio_console.c +15 -7
@@ -52,9 +52,9 @@ static struct chan_opts opts = { .in_kernel = 1, }; -static int con_config (char *str); +static int con_config (char *str,char **error_out);static int con_get_config (char *dev,char *str,int size,char **error_out); -static int con_remove (int n); +static int con_remove (int n,char **con_remove);static struct line_driver driver = { .name ="UML console" ,
@@ -87,9 +87,9 @@ static struct line vts[MAX_TTYS] = { LIN [ 1 ... MAX_TTYS - 1 ] = LINE_INIT(CONFIG_CON_CHAN, &driver) }; -static int con_config (char *str) +static int con_config (char *str,char **error_out) { -return line_config (vts,ARRAY_SIZE (vts), str, &opts); +return line_config (vts,ARRAY_SIZE (vts), str, &opts, error_out); }static int con_get_config (char *dev,char *str,int size,char **error_out)
@@ -97,9 +97,9 @@ static int con_get_config(char *dev, chareturn line_get_config (dev, vts,ARRAY_SIZE (vts), str, size, error_out); } -static int con_remove (int n) +static int con_remove (int n,char **error_out) { -return line_remove (vts,ARRAY_SIZE (vts), n); +return line_remove (vts,ARRAY_SIZE (vts), n, error_out); }static int con_open (struct tty_struct *tty,struct file *filp)
@@ -192,7 +192,15 @@ __uml_exitcall(console_exit);static int console_chan_setup (char *str) { -return line_setup (vts,ARRAY_SIZE (vts), str); +char *error; +int ret; + + ret =line_setup (vts,ARRAY_SIZE (vts), str, &error); +if (ret <0 ) +printk (KERN_ERR "Failed to set up console with " +"configuration string \"%s\" : %s\n" , str, error); + +return 1 ; }__setup ("con" , console_chan_setup);__channel_help (console_chan_setup,"con" );
arch/um/include/chan_kern.h +1 -1
@@ -30,7 +30,7 @@ struct chan {extern void chan_interrupt (struct list_head *chans,struct delayed_work *task,struct tty_struct *tty,int irq);extern int parse_chan_pair (char *str,struct line *line,int device, -const struct chan_opts *opts); +const struct chan_opts *opts,char **error_out);extern int open_chan (struct list_head *chans);extern int write_chan (struct list_head *chans,const char *buf,int len,int write_irq);
arch/um/include/line.h +5 -3
@@ -76,7 +76,7 @@ struct lines {extern void line_close (struct tty_struct *tty,struct file * filp);extern int line_open (struct line *lines,struct tty_struct *tty);extern int line_setup (struct line *lines,unsigned int sizeof_lines, -char *init); +char *init,char **error_out);extern int line_write (struct tty_struct *tty,const unsigned char *buf,int len);extern void line_put_char (struct tty_struct *tty,unsigned char ch);
@@ -102,9 +102,11 @@ extern void lines_init(struct line *lineextern void close_lines (struct line *lines,int nlines);extern int line_config (struct line *lines,unsigned int sizeof_lines, -char *str,const struct chan_opts *opts); +char *str,const struct chan_opts *opts, +char **error_out);extern int line_id (char **str,int *start_out,int *end_out); -extern int line_remove (struct line *lines,unsigned int sizeof_lines,int n); +extern int line_remove (struct line *lines,unsigned int sizeof_lines,int n, +char **error_out);extern int line_get_config (char *dev,struct line *lines,unsigned int sizeof_lines,char *str,int size,char **error_out);
arch/um/include/mconsole_kern.h +2 -13
@@ -18,10 +18,10 @@ struct mconsole_entry {struct mc_device {struct list_head list;char *name; -int (*config)(char *); +int (*config)(char *,char **);int (*get_config)(char *,char *,int ,char **);int (*id)(char **,int *,int *); -int (*remove)(int ); +int (*remove)(int ,char **); };#define CONFIG_CHUNK (str, size, current, chunk, end) \
@@ -50,14 +50,3 @@ static inline void mconsole_register_dev#endif #endif - -/* -* 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/kernel/tt/gdb.c +2 -2
@@ -139,7 +139,7 @@ static void config_gdb_cb(void *arg)init_proxy (debugger_pid,0 ,0 ); } -int gdb_config (char *str) +int gdb_config (char *str,char **error_out) {struct gdb_data data;
@@ -154,7 +154,7 @@ void remove_gdb_cb(void *unused)exit_debugger_cb (NULL ); } -int gdb_remove (int unused) +int gdb_remove (int unused,char **error_out) {initial_thread_cb (remove_gdb_cb,NULL );return 0 ;
arch/um/kernel/tt/gdb_kern.c +2 -2
@@ -8,8 +8,8 @@#ifdef CONFIG_MCONSOLE -extern int gdb_config (char *str); -extern int gdb_remove (int n); +extern int gdb_config (char *str,char **error_out); +extern int gdb_remove (int n,char **error_out);static struct mc_device gdb_mc = { .name = "gdb",
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel