aboutsummaryrefslogtreecommitdiff
path: root/arch/um/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/drivers')
-rw-r--r--arch/um/drivers/Makefile11
-rw-r--r--arch/um/drivers/chan_kern.c211
-rw-r--r--arch/um/drivers/chan_user.c211
-rw-r--r--arch/um/drivers/cow_user.c133
-rw-r--r--arch/um/drivers/daemon.h20
-rw-r--r--arch/um/drivers/daemon_kern.c34
-rw-r--r--arch/um/drivers/daemon_user.c92
-rw-r--r--arch/um/drivers/fd.c69
-rw-r--r--arch/um/drivers/harddog_kern.c2
-rw-r--r--arch/um/drivers/harddog_user.c58
-rw-r--r--arch/um/drivers/hostaudio_kern.c118
-rw-r--r--arch/um/drivers/line.c237
-rw-r--r--arch/um/drivers/mcast.h16
-rw-r--r--arch/um/drivers/mcast_kern.c56
-rw-r--r--arch/um/drivers/mcast_user.c73
-rw-r--r--arch/um/drivers/mconsole_kern.c289
-rw-r--r--arch/um/drivers/mconsole_user.c119
-rw-r--r--arch/um/drivers/mmapper_kern.c64
-rw-r--r--arch/um/drivers/net_kern.c278
-rw-r--r--arch/um/drivers/net_user.c126
-rw-r--r--arch/um/drivers/null.c28
-rw-r--r--arch/um/drivers/pcap_kern.c38
-rw-r--r--arch/um/drivers/pcap_user.c58
-rw-r--r--arch/um/drivers/port_kern.c86
-rw-r--r--arch/um/drivers/port_user.c73
-rw-r--r--arch/um/drivers/pty.c30
-rw-r--r--arch/um/drivers/slip_kern.c38
-rw-r--r--arch/um/drivers/slip_user.c129
-rw-r--r--arch/um/drivers/slirp_kern.c59
-rw-r--r--arch/um/drivers/slirp_user.c74
-rw-r--r--arch/um/drivers/tty.c37
-rw-r--r--arch/um/drivers/ubd_kern.c2
-rw-r--r--arch/um/drivers/vde.h32
-rw-r--r--arch/um/drivers/vde_kern.c129
-rw-r--r--arch/um/drivers/vde_user.c127
-rw-r--r--arch/um/drivers/xterm.c28
36 files changed, 1724 insertions, 1461 deletions
diff --git a/arch/um/drivers/Makefile b/arch/um/drivers/Makefile
index de17d4c6e02d..634968150bd6 100644
--- a/arch/um/drivers/Makefile
+++ b/arch/um/drivers/Makefile
@@ -19,10 +19,16 @@ harddog-objs := harddog_kern.o harddog_user.o
LDFLAGS_pcap.o := -r $(shell $(CC) $(CFLAGS) -print-file-name=libpcap.a)
-targets := pcap_kern.o pcap_user.o
+LDFLAGS_vde.o := -r $(shell $(CC) $(CFLAGS) -print-file-name=libvdeplug.a)
+
+targets := pcap_kern.o pcap_user.o vde_kern.o vde_user.o
$(obj)/pcap.o: $(obj)/pcap_kern.o $(obj)/pcap_user.o
$(LD) -r -dp -o $@ $^ $(LDFLAGS) $(LDFLAGS_pcap.o)
+
+$(obj)/vde.o: $(obj)/vde_kern.o $(obj)/vde_user.o
+ $(LD) -r -dp -o $@ $^ $(LDFLAGS) $(LDFLAGS_vde.o)
+
#XXX: The call below does not work because the flags are added before the
# object name, so nothing from the library gets linked.
#$(call if_changed,ld)
@@ -37,6 +43,7 @@ obj-$(CONFIG_STDERR_CONSOLE) += stderr_console.o
obj-$(CONFIG_UML_NET_SLIP) += slip.o slip_common.o
obj-$(CONFIG_UML_NET_SLIRP) += slirp.o slip_common.o
obj-$(CONFIG_UML_NET_DAEMON) += daemon.o
+obj-$(CONFIG_UML_NET_VDE) += vde.o
obj-$(CONFIG_UML_NET_MCAST) += mcast.o
obj-$(CONFIG_UML_NET_PCAP) += pcap.o
obj-$(CONFIG_UML_NET) += net.o
@@ -54,6 +61,6 @@ obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o
obj-$(CONFIG_UML_RANDOM) += random.o
# pcap_user.o must be added explicitly.
-USER_OBJS := fd.o null.o pty.o tty.o xterm.o slip_common.o pcap_user.o
+USER_OBJS := fd.o null.o pty.o tty.o xterm.o slip_common.o pcap_user.o vde_user.o
include arch/um/scripts/Makefile.rules
diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c
index 629b00e3b0b0..db3082b4da46 100644
--- a/arch/um/drivers/chan_kern.c
+++ b/arch/um/drivers/chan_kern.c
@@ -1,28 +1,19 @@
/*
- * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * 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 *str, int device,
static 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(int fd, const char *buf, int len)
static 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");
}
@@ -89,64 +80,17 @@ static const struct chan_ops not_configged_ops = {
};
#endif /* CONFIG_NOCONFIG_CHAN */
-void generic_close(int fd, void *unused)
-{
- os_close_file(fd);
-}
-
-int generic_read(int fd, char *c_out, void *unused)
-{
- int n;
-
- n = os_read_file(fd, c_out, sizeof(*c_out));
-
- if(n == -EAGAIN)
- return 0;
- else if(n == 0)
- return -EIO;
- return n;
-}
-
-/* XXX Trivial wrapper around os_write_file */
-
-int generic_write(int fd, const char *buf, int n, void *unused)
-{
- return os_write_file(fd, buf, n);
-}
-
-int generic_window_size(int fd, void *unused, unsigned short *rows_out,
- unsigned short *cols_out)
-{
- int rows, cols;
- int ret;
-
- ret = os_window_size(fd, &rows, &cols);
- if(ret < 0)
- return ret;
-
- ret = ((*rows_out != rows) || (*cols_out != cols));
-
- *rows_out = rows;
- *cols_out = cols;
-
- return ret;
-}
-
-void generic_free(void *data)
-{
- kfree(data);
-}
-
static 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;
}
@@ -159,14 +103,14 @@ static int open_one_chan(struct chan *chan)
{
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);
@@ -187,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;
@@ -201,9 +145,9 @@ void chan_enable_winch(struct list_head *chans, struct tty_struct *tty)
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 && chan->ops->winch){
+ if (chan->primary && chan->output && chan->ops->winch) {
register_winch(chan->fd, tty);
return;
}
@@ -216,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) {
@@ -226,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);
@@ -263,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;
}
@@ -278,22 +222,22 @@ static void close_one_chan(struct chan *chan, int delay_free_irq)
{
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;
@@ -322,7 +266,7 @@ void deactivate_chan(struct list_head *chans, int irq)
list_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);
}
}
@@ -335,7 +279,7 @@ void reactivate_chan(struct list_head *chans, int irq)
list_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);
}
}
@@ -347,10 +291,14 @@ int write_chan(struct list_head *chans, const char *buf, int len,
struct chan *chan = NULL;
int n, ret = 0;
+ if (len == 0)
+ return 0;
+
list_for_each(ele, 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;
@@ -367,12 +315,14 @@ int console_write_chan(struct list_head *chans, const char *buf, int len)
struct 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;
}
@@ -382,10 +332,11 @@ int console_open_chan(struct line *line, struct console *co)
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;
}
@@ -395,10 +346,10 @@ int chan_window_size(struct list_head *chans, unsigned short *rows_out,
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){
- 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);
@@ -413,10 +364,11 @@ static void free_one_chan(struct chan *chan, int delay_free_irq)
close_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);
}
@@ -425,7 +377,7 @@ static void free_chan(struct list_head *chans, int delay_free_irq)
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);
}
@@ -436,14 +388,14 @@ static int one_chan_config_string(struct chan *chan, char *str, int size,
{
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;
}
@@ -463,7 +415,7 @@ static int chan_pair_config_string(struct chan *in, struct chan *out,
str += n;
size -= n;
- if(in == out){
+ if (in == out) {
CONFIG_CHUNK(str, size, n, "", 1);
return n;
}
@@ -483,13 +435,13 @@ int chan_config_string(struct list_head *chans, char *str, int size,
struct 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;
}
@@ -548,27 +500,27 @@ static struct chan *parse_chan(struct line *line, char *str, int device,
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;
}
@@ -594,26 +546,26 @@ int parse_chan_pair(char *str, struct line *line, int device,
struct 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);
@@ -621,7 +573,7 @@ int parse_chan_pair(char *str, struct line *line, int device,
}
else {
new = parse_chan(line, str, device, opts, error_out);
- if(new == NULL)
+ if (new == NULL)
return -1;
list_add(&new->list, chans);
@@ -636,9 +588,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;
@@ -652,23 +604,25 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task,
int 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;
@@ -677,5 +631,6 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task,
}
}
out:
- if(tty) tty_flip_buffer_push(tty);
+ if (tty)
+ tty_flip_buffer_push(tty);
}
diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c
index 4d438f36ea2e..b88e93b3a39f 100644
--- a/arch/um/drivers/chan_user.c
+++ b/arch/um/drivers/chan_user.c
@@ -1,51 +1,107 @@
-/*
- * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
+/*
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL
*/
-#include <unistd.h>
#include <stdlib.h>
+#include <unistd.h>
#include <errno.h>
-#include <termios.h>
-#include <string.h>
-#include <signal.h>
#include <sched.h>
-#include <sys/stat.h>
+#include <signal.h>
+#include <termios.h>
#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include "kern_util.h"
#include "chan_user.h"
-#include "user.h"
#include "os.h"
-#include "choose-mode.h"
-#include "mode.h"
+#include "um_malloc.h"
+#include "user.h"
+
+void generic_close(int fd, void *unused)
+{
+ close(fd);
+}
+
+int generic_read(int fd, char *c_out, void *unused)
+{
+ int n;
+
+ n = read(fd, c_out, sizeof(*c_out));
+ if (n > 0)
+ return n;
+ else if (errno == EAGAIN)
+ return 0;
+ else if (n == 0)
+ return -EIO;
+ return -errno;
+}
+
+/* XXX Trivial wrapper around write */
+
+int generic_write(int fd, const char *buf, int n, void *unused)
+{
+ int err;
+
+ err = write(fd, buf, n);
+ if (err > 0)
+ return err;
+ else if (errno == EAGAIN)
+ return 0;
+ else if (err == 0)
+ return -EIO;
+ return -errno;
+}
+
+int generic_window_size(int fd, void *unused, unsigned short *rows_out,
+ unsigned short *cols_out)
+{
+ struct winsize size;
+ int ret;
+
+ if (ioctl(fd, TIOCGWINSZ, &size) < 0)
+ return -errno;
+
+ ret = ((*rows_out != size.ws_row) || (*cols_out != size.ws_col));
+
+ *rows_out = size.ws_row;
+ *cols_out = size.ws_col;
+
+ return ret;
+}
+
+void generic_free(void *data)
+{
+ kfree(data);
+}
int generic_console_write(int fd, const char *buf, int n)
{
struct termios save, new;
int err;
- if(isatty(fd)){
+ if (isatty(fd)) {
CATCH_EINTR(err = tcgetattr(fd, &save));
if (err)
goto error;
new = save;
- /* The terminal becomes a bit less raw, to handle \n also as
+ /*
+ * The terminal becomes a bit less raw, to handle \n also as
* "Carriage Return", not only as "New Line". Otherwise, the new
- * line won't start at the first column.*/
+ * line won't start at the first column.
+ */
new.c_oflag |= OPOST;
CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &new));
if (err)
goto error;
}
err = generic_write(fd, buf, n, NULL);
- /* Restore raw mode, in any case; we *must* ignore any error apart
- * EINTR, except for debug.*/
- if(isatty(fd))
+ /*
+ * Restore raw mode, in any case; we *must* ignore any error apart
+ * EINTR, except for debug.
+ */
+ if (isatty(fd))
CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
- return(err);
+ return err;
error:
- return(-errno);
+ return -errno;
}
/*
@@ -82,62 +138,73 @@ static int winch_thread(void *arg)
struct winch_data *data = arg;
sigset_t sigs;
int pty_fd, pipe_fd;
- int count, err;
+ int count;
char c = 1;
pty_fd = data->pty_fd;
pipe_fd = data->pipe_fd;
- count = os_write_file(pipe_fd, &c, sizeof(c));
- if(count != sizeof(c))
- printk("winch_thread : failed to write synchronization "
- "byte, err = %d\n", -count);
+ count = write(pipe_fd, &c, sizeof(c));
+ if (count != sizeof(c))
+ printk(UM_KERN_ERR "winch_thread : failed to write "
+ "synchronization byte, err = %d\n", -count);
- /* We are not using SIG_IGN on purpose, so don't fix it as I thought to
+ /*
+ * We are not using SIG_IGN on purpose, so don't fix it as I thought to
* do! If using SIG_IGN, the sigsuspend() call below would not stop on
- * SIGWINCH. */
+ * SIGWINCH.
+ */
signal(SIGWINCH, winch_handler);
sigfillset(&sigs);
/* Block all signals possible. */
- if(sigprocmask(SIG_SETMASK, &sigs, NULL) < 0){
- printk("winch_thread : sigprocmask failed, errno = %d\n",
- errno);
+ if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) {
+ printk(UM_KERN_ERR "winch_thread : sigprocmask failed, "
+ "errno = %d\n", errno);
exit(1);
}
/* In sigsuspend(), block anything else than SIGWINCH. */
sigdelset(&sigs, SIGWINCH);
- if(setsid() < 0){
- printk("winch_thread : setsid failed, errno = %d\n", errno);
+ if (setsid() < 0) {
+ printk(UM_KERN_ERR "winch_thread : setsid failed, errno = %d\n",
+ errno);
+ exit(1);
+ }
+
+ if (ioctl(pty_fd, TIOCSCTTY, 0) < 0) {
+ printk(UM_KERN_ERR "winch_thread : TIOCSCTTY failed on "
+ "fd %d err = %d\n", pty_fd, errno);
exit(1);
}
- err = os_new_tty_pgrp(pty_fd, os_getpid());
- if(err < 0){
- printk("winch_thread : new_tty_pgrp failed on fd %d, "
- "err = %d\n", pty_fd, -err);
+ if (tcsetpgrp(pty_fd, os_getpid()) < 0) {
+ printk(UM_KERN_ERR "winch_thread : tcsetpgrp failed on "
+ "fd %d err = %d\n", pty_fd, errno);
exit(1);
}
- /* These are synchronization calls between various UML threads on the
+ /*
+ * These are synchronization calls between various UML threads on the
* host - since they are not different kernel threads, we cannot use
* kernel semaphores. We don't use SysV semaphores because they are
- * persistent. */
- count = os_read_file(pipe_fd, &c, sizeof(c));
- if(count != sizeof(c))
- printk("winch_thread : failed to read synchronization byte, "
- "err = %d\n", -count);
-
- while(1){
- /* This will be interrupted by SIGWINCH only, since
+ * persistent.
+ */
+ count = read(pipe_fd, &c, sizeof(c));
+ if (count != sizeof(c))
+ printk(UM_KERN_ERR "winch_thread : failed to read "
+ "synchronization byte, err = %d\n", errno);
+
+ while(1) {
+ /*
+ * This will be interrupted by SIGWINCH only, since
* other signals are blocked.
*/
sigsuspend(&sigs);
- count = os_write_file(pipe_fd, &c, sizeof(c));
- if(count != sizeof(c))
- printk("winch_thread : write failed, err = %d\n",
- -count);
+ count = write(pipe_fd, &c, sizeof(c));
+ if (count != sizeof(c))
+ printk(UM_KERN_ERR "winch_thread : write failed, "
+ "err = %d\n", errno);
}
}
@@ -149,44 +216,49 @@ static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out,
char c;
err = os_pipe(fds, 1, 1);
- if(err < 0){
- printk("winch_tramp : os_pipe failed, err = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "winch_tramp : os_pipe failed, err = %d\n",
+ -err);
goto out;
}
data = ((struct winch_data) { .pty_fd = fd,
.pipe_fd = fds[1] } );
- /* CLONE_FILES so this thread doesn't hold open files which are open
+ /*
+ * CLONE_FILES so this thread doesn't hold open files which are open
* now, but later closed in a different thread. This is a
* problem with /dev/net/tun, which if held open by this
* thread, prevents the TUN/TAP device from being reused.
*/
err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out);
- if(err < 0){
- printk("fork of winch_thread failed - errno = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "fork of winch_thread failed - errno = %d\n",
+ -err);
goto out_close;
}
*fd_out = fds[0];
- n = os_read_file(fds[0], &c, sizeof(c));
- if(n != sizeof(c)){
- printk("winch_tramp : failed to read synchronization byte\n");
- printk("read failed, err = %d\n", -n);
- printk("fd %d will not support SIGWINCH\n", fd);
- err = -EINVAL;
+ n = read(fds[0], &c, sizeof(c));
+ if (n != sizeof(c)) {
+ printk(UM_KERN_ERR "winch_tramp : failed to read "
+ "synchronization byte\n");
+ printk(UM_KERN_ERR "read failed, err = %d\n", errno);
+ printk(UM_KERN_ERR "fd %d will not support SIGWINCH\n", fd);
+ err = -EINVAL;
goto out_close;
}
if (os_set_fd_block(*fd_out, 0)) {
- printk("winch_tramp: failed to set thread_fd non-blocking.\n");
+ printk(UM_KERN_ERR "winch_tramp: failed to set thread_fd "
+ "non-blocking.\n");
goto out_close;
}
return err;
out_close:
- os_close_file(fds[1]);
- os_close_file(fds[0]);
+ close(fds[1]);
+ close(fds[0]);
out:
return err;
}
@@ -197,21 +269,20 @@ void register_winch(int fd, struct tty_struct *tty)
int pid, thread, count, thread_fd = -1;
char c = 1;
- if(!isatty(fd))
+ if (!isatty(fd))
return;
pid = tcgetpgrp(fd);
- if (!CHOOSE_MODE_PROC(is_tracer_winch, is_skas_winch, pid, fd, tty) &&
- (pid == -1)) {
+ if (!is_skas_winch(pid, fd, tty) && (pid == -1)) {
thread = winch_tramp(fd, tty, &thread_fd, &stack);
if (thread < 0)
return;
register_winch_irq(thread_fd, fd, thread, tty, stack);
- count = os_write_file(thread_fd, &c, sizeof(c));
- if(count != sizeof(c))
- printk("register_winch : failed to write "
- "synchronization byte, err = %d\n", -count);
+ count = write(thread_fd, &c, sizeof(c));
+ if (count != sizeof(c))
+ printk(UM_KERN_ERR "register_winch : failed to write "
+ "synchronization byte, err = %d\n", errno);
}
}
diff --git a/arch/um/drivers/cow_user.c b/arch/um/drivers/cow_user.c
index 0ec4052db9c5..93f227a25ba4 100644
--- a/arch/um/drivers/cow_user.c
+++ b/arch/um/drivers/cow_user.c
@@ -1,17 +1,18 @@
-#include <stddef.h>
-#include <string.h>
-#include <errno.h>
-/* _XOPEN_SOURCE is needed for pread, but we define _GNU_SOURCE, which defines
+/*
+ * Copyright (C) 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
+ * Licensed under the GPL
+ */
+
+/*
+ * _XOPEN_SOURCE is needed for pread, but we define _GNU_SOURCE, which defines
* that.
*/
#include <unistd.h>
#include <byteswap.h>
-#include <sys/time.h>
-#include <sys/param.h>
-#include <sys/user.h>
-
-#include "os.h"
-
+#include <errno.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <asm/types.h>
#include "cow.h"
#include "cow_sys.h"
@@ -28,7 +29,8 @@ struct cow_header_v1 {
__s32 sectorsize;
} __attribute__((packed));
-/* Define PATH_LEN_V3 as the usual value of MAXPATHLEN, just hard-code it in
+/*
+ * Define PATH_LEN_V3 as the usual value of MAXPATHLEN, just hard-code it in
* case other systems have different values for MAXPATHLEN.
*
* The same must hold for V2 - we want file format compatibility, not anything
@@ -46,7 +48,8 @@ struct cow_header_v2 {
__s32 sectorsize;
} __attribute__((packed));
-/* Changes from V2 -
+/*
+ * Changes from V2 -
* PATH_LEN_V3 as described above
* Explicitly specify field bit lengths for systems with different
* lengths for the usual C types. Not sure whether char or
@@ -70,7 +73,8 @@ struct cow_header_v2 {
* Fixed (finally!) the rounding bug
*/
-/* Until Dec2005, __attribute__((packed)) was left out from the below
+/*
+ * Until Dec2005, __attribute__((packed)) was left out from the below
* definition, leading on 64-bit systems to 4 bytes of padding after mtime, to
* align size to 8-byte alignment. This shifted all fields above (no padding
* was present on 32-bit, no other padding was added).
@@ -122,7 +126,7 @@ void cow_sizes(int version, __u64 size, int sectorsize, int align,
int bitmap_offset, unsigned long *bitmap_len_out,
int *data_offset_out)
{
- if(version < 3){
+ if (version < 3) {
*bitmap_len_out = (size + sectorsize - 1) / (8 * sectorsize);
*data_offset_out = bitmap_offset + *bitmap_len_out;
@@ -144,46 +148,46 @@ static int absolutize(char *to, int size, char *from)
char save_cwd[256], *slash;
int remaining;
- if(getcwd(save_cwd, sizeof(save_cwd)) == NULL) {
+ if (getcwd(save_cwd, sizeof(save_cwd)) == NULL) {
cow_printf("absolutize : unable to get cwd - errno = %d\n",
errno);
- return(-1);
+ return -1;
}
slash = strrchr(from, '/');
- if(slash != NULL){
+ if (slash != NULL) {
*slash = '\0';
- if(chdir(from)){
+ if (chdir(from)) {
*slash = '/';
cow_printf("absolutize : Can't cd to '%s' - "
"errno = %d\n", from, errno);
- return(-1);
+ return -1;
}
*slash = '/';
- if(getcwd(to, size) == NULL){
+ if (getcwd(to, size) == NULL) {
cow_printf("absolutize : unable to get cwd of '%s' - "
"errno = %d\n", from, errno);
- return(-1);
+ return -1;
}
remaining = size - strlen(to);
- if(strlen(slash) + 1 > remaining){
+ if (strlen(slash) + 1 > remaining) {
cow_printf("absolutize : unable to fit '%s' into %d "
"chars\n", from, size);
- return(-1);
+ return -1;
}
strcat(to, slash);
}
else {
- if(strlen(save_cwd) + 1 + strlen(from) + 1 > size){
+ if (strlen(save_cwd) + 1 + strlen(from) + 1 > size) {
cow_printf("absolutize : unable to fit '%s' into %d "
"chars\n", from, size);
- return(-1);
+ return -1;
}
strcpy(to, save_cwd);
strcat(to, "/");
strcat(to, from);
}
chdir(save_cwd);
- return(0);
+ return 0;
}
int write_cow_header(char *cow_file, int fd, char *backing_file,
@@ -194,22 +198,23 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
int err;
err = cow_seek_file(fd, 0);
- if(err < 0){
+ if (err < 0) {
cow_printf("write_cow_header - lseek failed, err = %d\n", -err);
goto out;
}
err = -ENOMEM;
header = cow_malloc(sizeof(*header));
- if(header == NULL){
- cow_printf("write_cow_header - failed to allocate COW V3 header\n");
+ if (header == NULL) {
+ cow_printf("write_cow_header - failed to allocate COW V3 "
+ "header\n");
goto out;
}
header->magic = htonl(COW_MAGIC);
header->version = htonl(COW_VERSION);
err = -EINVAL;
- if(strlen(backing_file) > sizeof(header->backing_file) - 1){
+ if (strlen(backing_file) > sizeof(header->backing_file) - 1) {
/* Below, %zd is for a size_t value */
cow_printf("Backing file name \"%s\" is too long - names are "
"limited to %zd characters\n", backing_file,
@@ -217,12 +222,12 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
goto out_free;
}
- if(absolutize(header->backing_file, sizeof(header->backing_file),
+ if (absolutize(header->backing_file, sizeof(header->backing_file),
backing_file))
goto out_free;
err = os_file_modtime(header->backing_file, &modtime);
- if(err < 0){
+ if (err < 0) {
cow_printf("write_cow_header - backing file '%s' mtime "
"request failed, err = %d\n", header->backing_file,
-err);
@@ -230,7 +235,7 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
}
err = cow_file_size(header->backing_file, size);
- if(err < 0){
+ if (err < 0) {
cow_printf("write_cow_header - couldn't get size of "
"backing file '%s', err = %d\n",
header->backing_file, -err);
@@ -244,7 +249,7 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
header->cow_format = COW_BITMAP;
err = cow_write_file(fd, header, sizeof(*header));
- if(err != sizeof(*header)){
+ if (err != sizeof(*header)) {
cow_printf("write_cow_header - write of header to "
"new COW file '%s' failed, err = %d\n", cow_file,
-err);
@@ -254,14 +259,14 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
out_free:
cow_free(header);
out:
- return(err);
+ return err;
}
int file_reader(__u64 offset, char *buf, int len, void *arg)
{
int fd = *((int *) arg);
- return(pread(fd, buf, len, offset));
+ return pread(fd, buf, len, offset);
}
/* XXX Need to sanity-check the values read from the header */
@@ -278,31 +283,29 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
unsigned long version, magic;
header = cow_malloc(sizeof(*header));
- if(header == NULL){
+ if (header == NULL) {
cow_printf("read_cow_header - Failed to allocate header\n");
- return(-ENOMEM);
+ return -ENOMEM;
}
err = -EINVAL;
n = (*reader)(0, (char *) header, sizeof(*header), arg);
- if(n < offsetof(typeof(header->v1), backing_file)){
+ if (n < offsetof(typeof(header->v1), backing_file)) {
cow_printf("read_cow_header - short header\n");
goto out;
}
magic = header->v1.magic;
- if(magic == COW_MAGIC) {
+ if (magic == COW_MAGIC)
version = header->v1.version;
- }
- else if(magic == ntohl(COW_MAGIC)){
+ else if (magic == ntohl(COW_MAGIC))
version = ntohl(header->v1.version);
- }
/* No error printed because the non-COW case comes through here */
else goto out;
*version_out = version;
- if(version == 1){
- if(n < sizeof(header->v1)){
+ if (version == 1) {
+ if (n < sizeof(header->v1)) {
cow_printf("read_cow_header - failed to read V1 "
"header\n");
goto out;
@@ -314,8 +317,8 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
*align_out = *sectorsize_out;
file = header->v1.backing_file;
}
- else if(version == 2){
- if(n < sizeof(header->v2)){
+ else if (version == 2) {
+ if (n < sizeof(header->v2)) {
cow_printf("read_cow_header - failed to read V2 "
"header\n");
goto out;
@@ -328,8 +331,8 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
file = header->v2.backing_file;
}
/* This is very subtle - see above at union cow_header definition */
- else if(version == 3 && (*((int*)header->v3.backing_file) != 0)){
- if(n < sizeof(header->v3)){
+ else if (version == 3 && (*((int*)header->v3.backing_file) != 0)) {
+ if (n < sizeof(header->v3)) {
cow_printf("read_cow_header - failed to read V3 "
"header\n");
goto out;
@@ -345,17 +348,18 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
*bitmap_offset_out = ROUND_UP(sizeof(header->v3), *align_out);
file = header->v3.backing_file;
}
- else if(version == 3){
+ else if (version == 3) {
cow_printf("read_cow_header - broken V3 file with"
" 64-bit layout - recovering content.\n");
- if(n < sizeof(header->v3_b)){
+ if (n < sizeof(header->v3_b)) {
cow_printf("read_cow_header - failed to read V3 "
"header\n");
goto out;
}
- /* this was used until Dec2005 - 64bits are needed to represent
+ /*
+ * this was used until Dec2005 - 64bits are needed to represent
* 2038+. I.e. we can safely do this truncating cast.
*
* Additionally, we must use ntohl() instead of ntohll(), since
@@ -381,7 +385,7 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
}
err = -ENOMEM;
*backing_file_out = cow_strdup(file);
- if(*backing_file_out == NULL){
+ if (*backing_file_out == NULL) {
cow_printf("read_cow_header - failed to allocate backing "
"file\n");
goto out;
@@ -389,7 +393,7 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
err = 0;
out:
cow_free(header);
- return(err);
+ return err;
}
int init_cow_file(int fd, char *cow_file, char *backing_file, int sectorsize,
@@ -402,7 +406,7 @@ int init_cow_file(int fd, char *cow_file, char *backing_file, int sectorsize,
err = write_cow_header(cow_file, fd, backing_file, sectorsize,
alignment, &size);
- if(err)
+ if (err)
goto out;
*bitmap_offset_out = ROUND_UP(sizeof(struct cow_header_v3), alignment);
@@ -411,17 +415,18 @@ int init_cow_file(int fd, char *cow_file, char *backing_file, int sectorsize,
offset = *data_offset_out + size - sizeof(zero);
err = cow_seek_file(fd, offset);
- if(err < 0){
+ if (err < 0) {
cow_printf("cow bitmap lseek failed : err = %d\n", -err);
goto out;
}
- /* does not really matter how much we write it is just to set EOF
+ /*
+ * does not really matter how much we write it is just to set EOF
* this also sets the entire COW bitmap
* to zero without having to allocate it
*/
err = cow_write_file(fd, &zero, sizeof(zero));
- if(err != sizeof(zero)){
+ if (err != sizeof(zero)) {
cow_printf("Write of bitmap to new COW file '%s' failed, "
"err = %d\n", cow_file, -err);
if (err >= 0)
@@ -429,15 +434,7 @@ int init_cow_file(int fd, char *cow_file, char *backing_file, int sectorsize,
goto out;
}
- return(0);
-
+ return 0;
out:
- return(err);
+ return err;
}
-
-/*
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
diff --git a/arch/um/drivers/daemon.h b/arch/um/drivers/daemon.h
index 3bc3cf6b94aa..6e0e891f8a00 100644
--- a/arch/um/drivers/daemon.h
+++ b/arch/um/drivers/daemon.h
@@ -1,8 +1,11 @@
-/*
- * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
+#ifndef __DAEMON_H__
+#define __DAEMON_H__
+
#include "net_user.h"
#define SWITCH_VERSION 3
@@ -20,16 +23,7 @@ struct daemon_data {
extern const struct net_user_info daemon_user_info;
-extern int daemon_user_write(int fd, void *buf, int len,
+extern int daemon_user_write(int fd, void *buf, int len,
struct daemon_data *pri);
-/*
- * 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:
- */
+#endif
diff --git a/arch/um/drivers/daemon_kern.c b/arch/um/drivers/daemon_kern.c
index adeece11e596..d53ff52bb404 100644
--- a/arch/um/drivers/daemon_kern.c
+++ b/arch/um/drivers/daemon_kern.c
@@ -1,16 +1,14 @@
/*
- * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
+ * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 by various other people who didn't put their name here.
* Licensed under the GPL.
*/
-#include "linux/kernel.h"
#include "linux/init.h"
-#include "linux/netdevice.h"
-#include "linux/etherdevice.h"
+#include <linux/netdevice.h>
#include "net_kern.h"
-#include "net_user.h"
#include "daemon.h"
struct daemon_init {
@@ -36,25 +34,21 @@ static void daemon_init(struct net_device *dev, void *data)
dpri->data_addr = NULL;
dpri->local_addr = NULL;
- printk("daemon backend (uml_switch version %d) - %s:%s",
+ printk("daemon backend (uml_switch version %d) - %s:%s",
SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
printk("\n");
}
-static int daemon_read(int fd, struct sk_buff **skb,
- struct uml_net_private *lp)
+static int daemon_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
- if(*skb == NULL) return(-ENOMEM);
- return(net_recvfrom(fd, skb_mac_header(*skb),
- (*skb)->dev->mtu + ETH_HEADER_OTHER));
+ return net_recvfrom(fd, skb_mac_header(skb),
+ skb->dev->mtu + ETH_HEADER_OTHER);
}
-static int daemon_write(int fd, struct sk_buff **skb,
- struct uml_net_private *lp)
+static int daemon_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- return(daemon_user_write(fd, (*skb)->data, (*skb)->len,
- (struct daemon_data *) &lp->user));
+ return daemon_user_write(fd, skb->data, skb->len,
+ (struct daemon_data *) &lp->user);
}
static const struct net_kern_info daemon_kern_info = {
@@ -72,14 +66,14 @@ static int daemon_setup(char *str, char **mac_out, void *data)
*init = ((struct daemon_init)
{ .sock_type = "unix",
.ctl_sock = "/tmp/uml.ctl" });
-
+
remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
NULL);
- if(remain != NULL)
+ if (remain != NULL)
printk(KERN_WARNING "daemon_setup : Ignoring data socket "
"specification\n");
-
- return(1);
+
+ return 1;
}
static struct transport daemon_transport = {
diff --git a/arch/um/drivers/daemon_user.c b/arch/um/drivers/daemon_user.c
index 8d2008f06682..f23c109a055c 100644
--- a/arch/um/drivers/daemon_user.c
+++ b/arch/um/drivers/daemon_user.c
@@ -1,24 +1,23 @@
/*
- * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 by various other people who didn't put their name here.
* Licensed under the GPL.
*/
-#include <errno.h>
-#include <unistd.h>
#include <stdint.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/un.h>
#include <sys/time.h>
-#include "net_user.h"
+#include <sys/un.h>
#include "daemon.h"
-#include "kern_util.h"
-#include "user.h"
+#include "net_user.h"
#include "os.h"
#include "um_malloc.h"
-
-#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
+#include "user.h"
enum request_type { REQ_NEW_CONTROL };
@@ -36,8 +35,9 @@ static struct sockaddr_un *new_addr(void *name, int len)
struct sockaddr_un *sun;
sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
- if(sun == NULL){
- printk("new_addr: allocation of sockaddr_un failed\n");
+ if (sun == NULL) {
+ printk(UM_KERN_ERR "new_addr: allocation of sockaddr_un "
+ "failed\n");
return NULL;
}
sun->sun_family = AF_UNIX;
@@ -54,38 +54,39 @@ static int connect_to_switch(struct daemon_data *pri)
int fd, n, err;
pri->control = socket(AF_UNIX, SOCK_STREAM, 0);
- if(pri->control < 0){
+ if (pri->control < 0) {
err = -errno;
- printk("daemon_open : control socket failed, errno = %d\n",
- -err);
+ printk(UM_KERN_ERR "daemon_open : control socket failed, "
+ "errno = %d\n", -err);
return err;
}
- if(connect(pri->control, (struct sockaddr *) ctl_addr,
- sizeof(*ctl_addr)) < 0){
+ if (connect(pri->control, (struct sockaddr *) ctl_addr,
+ sizeof(*ctl_addr)) < 0) {
err = -errno;
- printk("daemon_open : control connect failed, errno = %d\n",
- -err);
+ printk(UM_KERN_ERR "daemon_open : control connect failed, "
+ "errno = %d\n", -err);
goto out;
}
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
- if(fd < 0){
+ if (fd < 0) {
err = -errno;
- printk("daemon_open : data socket failed, errno = %d\n",
- -err);
+ printk(UM_KERN_ERR "daemon_open : data socket failed, "
+ "errno = %d\n", -err);
goto out;
}
- if(bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0){
+ if (bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0) {
err = -errno;
- printk("daemon_open : data bind failed, errno = %d\n",
- -err);
+ printk(UM_KERN_ERR "daemon_open : data bind failed, "
+ "errno = %d\n", -err);
goto out_close;
}
sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
- if(sun == NULL){
- printk("new_addr: allocation of sockaddr_un failed\n");
+ if (sun == NULL) {
+ printk(UM_KERN_ERR "new_addr: allocation of sockaddr_un "
+ "failed\n");
err = -ENOMEM;
goto out_close;
}
@@ -94,18 +95,18 @@ static int connect_to_switch(struct daemon_data *pri)
req.version = SWITCH_VERSION;
req.type = REQ_NEW_CONTROL;
req.sock = *local_addr;
- n = os_write_file(pri->control, &req, sizeof(req));
- if(n != sizeof(req)){
- printk("daemon_open : control setup request failed, err = %d\n",
- -n);
+ n = write(pri->control, &req, sizeof(req));
+ if (n != sizeof(req)) {
+ printk(UM_KERN_ERR "daemon_open : control setup request "
+ "failed, err = %d\n", -errno);
err = -ENOTCONN;
goto out_free;
}
- n = os_read_file(pri->control, sun, sizeof(*sun));
- if(n != sizeof(*sun)){
- printk("daemon_open : read of data socket failed, err = %d\n",
- -n);
+ n = read(pri->control, sun, sizeof(*sun));
+ if (n != sizeof(*sun)) {
+ printk(UM_KERN_ERR "daemon_open : read of data socket failed, "
+ "err = %d\n", -errno);
err = -ENOTCONN;
goto out_free;
}
@@ -116,9 +117,9 @@ static int connect_to_switch(struct daemon_data *pri)
out_free:
kfree(sun);
out_close:
- os_close_file(fd);
+ close(fd);
out:
- os_close_file(pri->control);
+ close(pri->control);
return err;
}
@@ -132,8 +133,8 @@ static int daemon_user_init(void *data, void *dev)
int usecs;
} name;
- if(!strcmp(pri->sock_type, "unix"))
- pri->ctl_addr = new_addr(pri->ctl_sock,
+ if (!strcmp(pri->sock_type, "unix"))
+ pri->ctl_addr = new_addr(pri->ctl_sock,
strlen(pri->ctl_sock) + 1);
name.zero = 0;
name.pid = os_getpid();
@@ -142,7 +143,7 @@ static int daemon_user_init(void *data, void *dev)
pri->local_addr = new_addr(&name, sizeof(name));
pri->dev = dev;
pri->fd = connect_to_switch(pri);
- if(pri->fd < 0){
+ if (pri->fd < 0) {
kfree(pri->local_addr);
pri->local_addr = NULL;
return pri->fd;
@@ -161,9 +162,9 @@ static void daemon_remove(void *data)
{
struct daemon_data *pri = data;
- os_close_file(pri->fd);
+ close(pri->fd);
pri->fd = -1;
- os_close_file(pri->control);
+ close(pri->control);
pri->control = -1;
kfree(pri->data_addr);
@@ -181,18 +182,13 @@ int daemon_user_write(int fd, void *buf, int len, struct daemon_data *pri)
return net_sendto(fd, buf, len, data_addr, sizeof(*data_addr));
}
-static int daemon_set_mtu(int mtu, void *data)
-{
- return mtu;
-}
-
const struct net_user_info daemon_user_info = {
.init = daemon_user_init,
.open = daemon_open,
.close = NULL,
.remove = daemon_remove,
- .set_mtu = daemon_set_mtu,
.add_address = NULL,
.delete_address = NULL,
- .max_packet = MAX_PACKET - ETH_HEADER_OTHER
+ .mtu = ETH_MAX_PACKET,
+ .max_packet = ETH_MAX_PACKET + ETH_HEADER_OTHER,
};
diff --git a/arch/um/drivers/fd.c b/arch/um/drivers/fd.c
index 39c01ffd45c9..0a2bb5b64b82 100644
--- a/arch/um/drivers/fd.c
+++ b/arch/um/drivers/fd.c
@@ -1,17 +1,18 @@
-/*
- * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <termios.h>
#include <errno.h>
-#include "user.h"
+#include <termios.h>
#include "chan_user.h"
+#include "kern_constants.h"
#include "os.h"
#include "um_malloc.h"
+#include "user.h"
struct fd_chan {
int fd;
@@ -26,22 +27,26 @@ static void *fd_init(char *str, int device, const struct chan_opts *opts)
char *end;
int n;
- if(*str != ':'){
- printk("fd_init : channel type 'fd' must specify a file "
- "descriptor\n");
- return(NULL);
+ if (*str != ':') {
+ printk(UM_KERN_ERR "fd_init : channel type 'fd' must specify a "
+ "file descriptor\n");
+ return NULL;
}
str++;
n = strtoul(str, &end, 0);
- if((*end != '\0') || (end == str)){
- printk("fd_init : couldn't parse file descriptor '%s'\n", str);
- return(NULL);
+ if ((*end != '\0') || (end == str)) {
+ printk(UM_KERN_ERR "fd_init : couldn't parse file descriptor "
+ "'%s'\n", str);
+ return NULL;
}
+
data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
- if(data == NULL) return(NULL);
+ if (data == NULL)
+ return NULL;
+
*data = ((struct fd_chan) { .fd = n,
.raw = opts->raw });
- return(data);
+ return data;
}
static int fd_open(int input, int output, int primary, void *d, char **dev_out)
@@ -49,18 +54,18 @@ static int fd_open(int input, int output, int primary, void *d, char **dev_out)
struct fd_chan *data = d;
int err;
- if(data->raw && isatty(data->fd)){
+ if (data->raw && isatty(data->fd)) {
CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
- if(err)
- return(err);
+ if (err)
+ return err;
err = raw(data->fd);
- if(err)
- return(err);
+ if (err)
+ return err;
}
sprintf(data->str, "%d", data->fd);
*dev_out = data->str;
- return(data->fd);
+ return data->fd;
}
static void fd_close(int fd, void *d)
@@ -68,13 +73,14 @@ static void fd_close(int fd, void *d)
struct fd_chan *data = d;
int err;
- if(data->raw && isatty(fd)){
- CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
- if(err)
- printk("Failed to restore terminal state - "
- "errno = %d\n", -err);
- data->raw = 0;
- }
+ if (!data->raw || !isatty(fd))
+ return;
+
+ CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
+ if (err)
+ printk(UM_KERN_ERR "Failed to restore terminal state - "
+ "errno = %d\n", -err);
+ data->raw = 0;
}
const struct chan_ops fd_ops = {
@@ -89,14 +95,3 @@ const struct chan_ops fd_ops = {
.free = generic_free,
.winch = 1,
};
-
-/*
- * 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:
- */
diff --git a/arch/um/drivers/harddog_kern.c b/arch/um/drivers/harddog_kern.c
index 55601687b3bc..a9ad4bd6d953 100644
--- a/arch/um/drivers/harddog_kern.c
+++ b/arch/um/drivers/harddog_kern.c
@@ -69,7 +69,7 @@ static int harddog_open(struct inode *inode, struct file *file)
spin_lock(&lock);
if(timer_alive)
goto err;
-#ifdef CONFIG_HARDDOG_NOWAYOUT
+#ifdef CONFIG_WATCHDOG_NOWAYOUT
__module_get(THIS_MODULE);
#endif
diff --git a/arch/um/drivers/harddog_user.c b/arch/um/drivers/harddog_user.c
index 1171790f742c..b56f8e0196a9 100644
--- a/arch/um/drivers/harddog_user.c
+++ b/arch/um/drivers/harddog_user.c
@@ -1,16 +1,13 @@
/*
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
-#include "user.h"
-#include "mconsole.h"
#include "os.h"
-#include "choose-mode.h"
-#include "mode.h"
+#include "user.h"
struct dog_data {
int stdin;
@@ -25,10 +22,10 @@ static void pre_exec(void *d)
dup2(data->stdin, 0);
dup2(data->stdout, 1);
dup2(data->stdout, 2);
- os_close_file(data->stdin);
- os_close_file(data->stdout);
- os_close_file(data->close_me[0]);
- os_close_file(data->close_me[1]);
+ close(data->stdin);
+ close(data->stdout);
+ close(data->close_me[0]);
+ close(data->close_me[1]);
}
int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock)
@@ -42,13 +39,13 @@ int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock)
char **args = NULL;
err = os_pipe(in_fds, 1, 0);
- if(err < 0){
+ if (err < 0) {
printk("harddog_open - os_pipe failed, err = %d\n", -err);
goto out;
}
err = os_pipe(out_fds, 1, 0);
- if(err < 0){
+ if (err < 0) {
printk("harddog_open - os_pipe failed, err = %d\n", -err);
goto out_close_in;
}
@@ -58,37 +55,37 @@ int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock)
data.close_me[0] = out_fds[1];
data.close_me[1] = in_fds[0];
- if(sock != NULL){
+ if (sock != NULL) {
mconsole_args[2] = sock;
args = mconsole_args;
}
else {
/* XXX The os_getpid() is not SMP correct */
- sprintf(pid_buf, "%d", CHOOSE_MODE(tracing_pid, os_getpid()));
+ sprintf(pid_buf, "%d", os_getpid());
args = pid_args;
}
pid = run_helper(pre_exec, &data, args);
- os_close_file(out_fds[0]);
- os_close_file(in_fds[1]);
+ close(out_fds[0]);
+ close(in_fds[1]);
- if(pid < 0){
+ if (pid < 0) {
err = -pid;
printk("harddog_open - run_helper failed, errno = %d\n", -err);
goto out_close_out;
}
- n = os_read_file(in_fds[0], &c, sizeof(c));
- if(n == 0){
+ n = read(in_fds[0], &c, sizeof(c));
+ if (n == 0) {
printk("harddog_open - EOF on watchdog pipe\n");
helper_wait(pid);
err = -EIO;
goto out_close_out;
}
- else if(n < 0){
+ else if (n < 0) {
printk("harddog_open - read of watchdog pipe failed, "
- "err = %d\n", -n);
+ "err = %d\n", errno);
helper_wait(pid);
err = n;
goto out_close_out;
@@ -98,19 +95,19 @@ int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock)
return 0;
out_close_in:
- os_close_file(in_fds[0]);
- os_close_file(in_fds[1]);
+ close(in_fds[0]);
+ close(in_fds[1]);
out_close_out:
- os_close_file(out_fds[0]);
- os_close_file(out_fds[1]);
+ close(out_fds[0]);
+ close(out_fds[1]);
out:
return err;
}
void stop_watchdog(int in_fd, int out_fd)
{
- os_close_file(in_fd);
- os_close_file(out_fd);
+ close(in_fd);
+ close(out_fd);
}
int ping_watchdog(int fd)
@@ -118,10 +115,11 @@ int ping_watchdog(int fd)
int n;
char c = '\n';
- n = os_write_file(fd, &c, sizeof(c));
- if(n != sizeof(c)){
- printk("ping_watchdog - write failed, err = %d\n", -n);
- if(n < 0)
+ n = write(fd, &c, sizeof(c));
+ if (n != sizeof(c)) {
+ printk("ping_watchdog - write failed, ret = %d, err = %d\n",
+ n, errno);
+ if (n < 0)
return n;
return -EIO;
}
diff --git a/arch/um/drivers/hostaudio_kern.c b/arch/um/drivers/hostaudio_kern.c
index 10e08a8c17c3..ff1b22b69e9c 100644
--- a/arch/um/drivers/hostaudio_kern.c
+++ b/arch/um/drivers/hostaudio_kern.c
@@ -1,16 +1,14 @@
-/*
- * Copyright (C) 2002 Steve Schmidtke
+/*
+ * Copyright (C) 2002 Steve Schmidtke
* Licensed under the GPL
*/
+#include "linux/fs.h"
#include "linux/module.h"
-#include "linux/init.h"
#include "linux/slab.h"
-#include "linux/fs.h"
#include "linux/sound.h"
#include "linux/soundcard.h"
#include "asm/uaccess.h"
-#include "kern_util.h"
#include "init.h"
#include "os.h"
@@ -25,7 +23,8 @@ struct hostmixer_state {
#define HOSTAUDIO_DEV_DSP "/dev/sound/dsp"
#define HOSTAUDIO_DEV_MIXER "/dev/sound/mixer"
-/* Changed either at boot time or module load time. At boot, this is
+/*
+ * Changed either at boot time or module load time. At boot, this is
* single-threaded; at module load, multiple modules would each have
* their own copy of these variables.
*/
@@ -44,7 +43,7 @@ static char *mixer = HOSTAUDIO_DEV_MIXER;
static int set_dsp(char *name, int *add)
{
dsp = name;
- return(0);
+ return 0;
}
__uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP);
@@ -52,7 +51,7 @@ __uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP);
static int set_mixer(char *name, int *add)
{
mixer = name;
- return(0);
+ return 0;
}
__uml_setup("mixer=", set_mixer, "mixer=<mixer device>\n" MIXER_HELP);
@@ -77,23 +76,23 @@ static ssize_t hostaudio_read(struct file *file, char __user *buffer,
int err;
#ifdef DEBUG
- printk("hostaudio: read called, count = %d\n", count);
+ printk(KERN_DEBUG "hostaudio: read called, count = %d\n", count);
#endif
kbuf = kmalloc(count, GFP_KERNEL);
- if(kbuf == NULL)
- return(-ENOMEM);
+ if (kbuf == NULL)
+ return -ENOMEM;
err = os_read_file(state->fd, kbuf, count);
- if(err < 0)
+ if (err < 0)
goto out;
- if(copy_to_user(buffer, kbuf, err))
+ if (copy_to_user(buffer, kbuf, err))
err = -EFAULT;
out:
kfree(kbuf);
- return(err);
+ return err;
}
static ssize_t hostaudio_write(struct file *file, const char __user *buffer,
@@ -104,40 +103,40 @@ static ssize_t hostaudio_write(struct file *file, const char __user *buffer,
int err;
#ifdef DEBUG
- printk("hostaudio: write called, count = %d\n", count);
+ printk(KERN_DEBUG "hostaudio: write called, count = %d\n", count);
#endif
kbuf = kmalloc(count, GFP_KERNEL);
- if(kbuf == NULL)
- return(-ENOMEM);
+ if (kbuf == NULL)
+ return -ENOMEM;
err = -EFAULT;
- if(copy_from_user(kbuf, buffer, count))
+ if (copy_from_user(kbuf, buffer, count))
goto out;
err = os_write_file(state->fd, kbuf, count);
- if(err < 0)
+ if (err < 0)
goto out;
*ppos += err;
out:
kfree(kbuf);
- return(err);
+ return err;
}
-static unsigned int hostaudio_poll(struct file *file,
+static unsigned int hostaudio_poll(struct file *file,
struct poll_table_struct *wait)
{
unsigned int mask = 0;
#ifdef DEBUG
- printk("hostaudio: poll called (unimplemented)\n");
+ printk(KERN_DEBUG "hostaudio: poll called (unimplemented)\n");
#endif
- return(mask);
+ return mask;
}
-static int hostaudio_ioctl(struct inode *inode, struct file *file,
+static int hostaudio_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct hostaudio_state *state = file->private_data;
@@ -145,7 +144,7 @@ static int hostaudio_ioctl(struct inode *inode, struct file *file,
int err;
#ifdef DEBUG
- printk("hostaudio: ioctl called, cmd = %u\n", cmd);
+ printk(KERN_DEBUG "hostaudio: ioctl called, cmd = %u\n", cmd);
#endif
switch(cmd){
case SNDCTL_DSP_SPEED:
@@ -154,8 +153,8 @@ static int hostaudio_ioctl(struct inode *inode, struct file *file,
case SNDCTL_DSP_CHANNELS:
case SNDCTL_DSP_SUBDIVIDE:
case SNDCTL_DSP_SETFRAGMENT:
- if(get_user(data, (int __user *) arg))
- return(-EFAULT);
+ if (get_user(data, (int __user *) arg))
+ return EFAULT;
break;
default:
break;
@@ -170,14 +169,14 @@ static int hostaudio_ioctl(struct inode *inode, struct file *file,
case SNDCTL_DSP_CHANNELS:
case SNDCTL_DSP_SUBDIVIDE:
case SNDCTL_DSP_SETFRAGMENT:
- if(put_user(data, (int __user *) arg))
- return(-EFAULT);
+ if (put_user(data, (int __user *) arg))
+ return -EFAULT;
break;
default:
break;
}
- return(err);
+ return err;
}
static int hostaudio_open(struct inode *inode, struct file *file)
@@ -187,24 +186,26 @@ static int hostaudio_open(struct inode *inode, struct file *file)
int ret;
#ifdef DEBUG
- printk("hostaudio: open called (host: %s)\n", dsp);
+ printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp);
#endif
state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
- if(state == NULL)
- return(-ENOMEM);
+ if (state == NULL)
+ return -ENOMEM;
- if(file->f_mode & FMODE_READ) r = 1;
- if(file->f_mode & FMODE_WRITE) w = 1;
+ if (file->f_mode & FMODE_READ)
+ r = 1;
+ if (file->f_mode & FMODE_WRITE)
+ w = 1;
ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
- if(ret < 0){
+ if (ret < 0) {
kfree(state);
- return(ret);
+ return ret;
}
state->fd = ret;
file->private_data = state;
- return(0);
+ return 0;
}
static int hostaudio_release(struct inode *inode, struct file *file)
@@ -212,26 +213,26 @@ static int hostaudio_release(struct inode *inode, struct file *file)
struct hostaudio_state *state = file->private_data;
#ifdef DEBUG
- printk("hostaudio: release called\n");
+ printk(KERN_DEBUG "hostaudio: release called\n");
#endif
os_close_file(state->fd);
kfree(state);
- return(0);
+ return 0;
}
/* /dev/mixer file operations */
-static int hostmixer_ioctl_mixdev(struct inode *inode, struct file *file,
+static int hostmixer_ioctl_mixdev(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct hostmixer_state *state = file->private_data;
#ifdef DEBUG
- printk("hostmixer: ioctl called\n");
+ printk(KERN_DEBUG "hostmixer: ioctl called\n");
#endif
- return(os_ioctl_generic(state->fd, cmd, arg));
+ return os_ioctl_generic(state->fd, cmd, arg);
}
static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
@@ -241,26 +242,29 @@ static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
int ret;
#ifdef DEBUG
- printk("hostmixer: open called (host: %s)\n", mixer);
+ printk(KERN_DEBUG "hostmixer: open called (host: %s)\n", mixer);
#endif
state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL);
- if(state == NULL) return(-ENOMEM);
+ if (state == NULL)
+ return -ENOMEM;
- if(file->f_mode & FMODE_READ) r = 1;
- if(file->f_mode & FMODE_WRITE) w = 1;
+ if (file->f_mode & FMODE_READ)
+ r = 1;
+ if (file->f_mode & FMODE_WRITE)
+ w = 1;
ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
-
- if(ret < 0){
- printk("hostaudio_open_mixdev failed to open '%s', err = %d\n",
- dsp, -ret);
+
+ if (ret < 0) {
+ printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', "
+ "err = %d\n", dsp, -ret);
kfree(state);
- return(ret);
+ return ret;
}
file->private_data = state;
- return(0);
+ return 0;
}
static int hostmixer_release(struct inode *inode, struct file *file)
@@ -268,13 +272,13 @@ static int hostmixer_release(struct inode *inode, struct file *file)
struct hostmixer_state *state = file->private_data;
#ifdef DEBUG
- printk("hostmixer: release called\n");
+ printk(KERN_DEBUG "hostmixer: release called\n");
#endif
os_close_file(state->fd);
kfree(state);
- return(0);
+ return 0;
}
/* kernel module operations */
@@ -314,13 +318,13 @@ static int __init hostaudio_init_module(void)
dsp, mixer);
module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
- if(module_data.dev_audio < 0){
+ if (module_data.dev_audio < 0) {
printk(KERN_ERR "hostaudio: couldn't register DSP device!\n");
return -ENODEV;
}
module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1);
- if(module_data.dev_mixer < 0){
+ if (module_data.dev_mixer < 0) {
printk(KERN_ERR "hostmixer: couldn't register mixer "
"device!\n");
unregister_sound_dsp(module_data.dev_audio);
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 3e0b68e297f2..76fe0b0da996 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -1,22 +1,14 @@
/*
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
-#include "linux/kernel.h"
-#include "linux/sched.h"
-#include "linux/slab.h"
-#include "linux/list.h"
+#include "linux/irqreturn.h"
#include "linux/kd.h"
-#include "linux/interrupt.h"
-#include "asm/uaccess.h"
#include "chan_kern.h"
+#include "irq_kern.h"
#include "irq_user.h"
-#include "line.h"
-#include "kern.h"
-#include "kern_util.h"
#include "os.h"
-#include "irq_kern.h"
#define LINE_BUFSIZE 4096
@@ -35,12 +27,13 @@ static void line_timer_cb(struct work_struct *work)
{
struct line *line = container_of(work, struct line, task.work);
- if(!line->throttled)
+ if (!line->throttled)
chan_interrupt(&line->chan_list, &line->task, line->tty,
line->driver->read_irq);
}
-/* Returns the free space inside the ring buffer of this line.
+/*
+ * Returns the free space inside the ring buffer of this line.
*
* Should be called while holding line->lock (this does not modify datas).
*/
@@ -107,11 +100,12 @@ static int buffer_data(struct line *line, const char *buf, int len)
{
int end, room;
- if(line->buffer == NULL){
+ if (line->buffer == NULL) {
line->buffer = kmalloc(LINE_BUFSIZE, GFP_ATOMIC);
if (line->buffer == NULL) {
- printk("buffer_data - atomic allocation failed\n");
- return(0);
+ printk(KERN_ERR "buffer_data - atomic allocation "
+ "failed\n");
+ return 0;
}
line->head = line->buffer;
line->tail = line->buffer;
@@ -122,7 +116,7 @@ static int buffer_data(struct line *line, const char *buf, int len)
end = line->buffer + LINE_BUFSIZE - line->tail;
- if (len < end){
+ if (len < end) {
memcpy(line->tail, buf, len);
line->tail += len;
}
@@ -162,8 +156,10 @@ static int flush_buffer(struct line *line)
if (n < 0)
return n;
if (n == count) {
- /* We have flushed from ->head to buffer end, now we
- * must flush only from the beginning to ->tail.*/
+ /*
+ * We have flushed from ->head to buffer end, now we
+ * must flush only from the beginning to ->tail.
+ */
line->head = line->buffer;
} else {
line->head += n;
@@ -175,7 +171,7 @@ static int flush_buffer(struct line *line)
n = write_chan(&line->chan_list, line->head, count,
line->driver->write_irq);
- if(n < 0)
+ if (n < 0)
return n;
line->head += n;
@@ -189,19 +185,18 @@ void line_flush_buffer(struct tty_struct *tty)
int err;
/*XXX: copied from line_write, verify if it is correct!*/
- if(tty->stopped)
+ if (tty->stopped)
return;
spin_lock_irqsave(&line->lock, flags);
err = flush_buffer(line);
- /*if (err == 1)
- err = 0;*/
spin_unlock_irqrestore(&line->lock, flags);
- //return err;
}
-/* We map both ->flush_chars and ->put_char (which go in pair) onto ->flush_buffer
- * and ->write. Hope it's not that bad.*/
+/*
+ * We map both ->flush_chars and ->put_char (which go in pair) onto
+ * ->flush_buffer and ->write. Hope it's not that bad.
+ */
void line_flush_chars(struct tty_struct *tty)
{
line_flush_buffer(tty);
@@ -216,18 +211,15 @@ int line_write(struct tty_struct *tty, const unsigned char *buf, int len)
{
struct line *line = tty->driver_data;
unsigned long flags;
- int n, err, ret = 0;
+ int n, ret = 0;
- if(tty->stopped)
+ if (tty->stopped)
return 0;
spin_lock_irqsave(&line->lock, flags);
- if (line->head != line->tail) {
+ if (line->head != line->tail)
ret = buffer_data(line, buf, len);
- err = flush_buffer(line);
- if (err <= 0 && (err != -EAGAIN || !ret))
- ret = err;
- } else {
+ else {
n = write_chan(&line->chan_list, buf, len,
line->driver->write_irq);
if (n < 0) {
@@ -257,17 +249,17 @@ static const struct {
} tty_ioctls[] = {
/* don't print these, they flood the log ... */
{ TCGETS, NULL, "TCGETS" },
- { TCSETS, NULL, "TCSETS" },
- { TCSETSW, NULL, "TCSETSW" },
- { TCFLSH, NULL, "TCFLSH" },
- { TCSBRK, NULL, "TCSBRK" },
+ { TCSETS, NULL, "TCSETS" },
+ { TCSETSW, NULL, "TCSETSW" },
+ { TCFLSH, NULL, "TCFLSH" },
+ { TCSBRK, NULL, "TCSBRK" },
/* general tty stuff */
- { TCSETSF, KERN_DEBUG, "TCSETSF" },
- { TCGETA, KERN_DEBUG, "TCGETA" },
- { TIOCMGET, KERN_DEBUG, "TIOCMGET" },
- { TCSBRKP, KERN_DEBUG, "TCSBRKP" },
- { TIOCMSET, KERN_DEBUG, "TIOCMSET" },
+ { TCSETSF, KERN_DEBUG, "TCSETSF" },
+ { TCGETA, KERN_DEBUG, "TCGETA" },
+ { TIOCMGET, KERN_DEBUG, "TIOCMGET" },
+ { TCSBRKP, KERN_DEBUG, "TCSBRKP" },
+ { TIOCMSET, KERN_DEBUG, "TIOCMSET" },
/* linux-specific ones */
{ TIOCLINUX, KERN_INFO, "TIOCLINUX" },
@@ -324,12 +316,7 @@ int line_ioctl(struct tty_struct *tty, struct file * file,
for (i = 0; i < ARRAY_SIZE(tty_ioctls); i++)
if (cmd == tty_ioctls[i].cmd)
break;
- if (i < ARRAY_SIZE(tty_ioctls)) {
- if (NULL != tty_ioctls[i].level)
- printk("%s%s: %s: ioctl %s called\n",
- tty_ioctls[i].level, __FUNCTION__,
- tty->name, tty_ioctls[i].name);
- } else {
+ if (i == ARRAY_SIZE(tty_ioctls)) {
printk(KERN_ERR "%s: %s: unknown ioctl: 0x%x\n",
__FUNCTION__, tty->name, cmd);
}
@@ -355,11 +342,12 @@ void line_unthrottle(struct tty_struct *tty)
chan_interrupt(&line->chan_list, &line->task, tty,
line->driver->read_irq);
- /* Maybe there is enough stuff pending that calling the interrupt
+ /*
+ * Maybe there is enough stuff pending that calling the interrupt
* throttles us again. In this case, line->throttled will be 1
* again and we shouldn't turn the interrupt back on.
*/
- if(!line->throttled)
+ if (!line->throttled)
reactivate_chan(&line->chan_list, line->driver->read_irq);
}
@@ -370,27 +358,30 @@ static irqreturn_t line_write_interrupt(int irq, void *data)
struct tty_struct *tty = line->tty;
int err;
- /* Interrupts are disabled here because we registered the interrupt with
- * IRQF_DISABLED (see line_setup_irq).*/
+ /*
+ * Interrupts are disabled here because we registered the interrupt with
+ * IRQF_DISABLED (see line_setup_irq).
+ */
spin_lock(&line->lock);
err = flush_buffer(line);
if (err == 0) {
return IRQ_NONE;
- } else if(err < 0) {
+ } else if (err < 0) {
line->head = line->buffer;
line->tail = line->buffer;
}
spin_unlock(&line->lock);
- if(tty == NULL)
+ if (tty == NULL)
return IRQ_NONE;
if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags) &&
(tty->ldisc.write_wakeup != NULL))
(tty->ldisc.write_wakeup)(tty);
- /* BLOCKING mode
+ /*
+ * BLOCKING mode
* In blocking mode, everything sleeps on tty->write_wait.
* Sleeping in the console driver would break non-blocking
* writes.
@@ -420,7 +411,8 @@ int line_setup_irq(int fd, int input, int output, struct line *line, void *data)
return err;
}
-/* Normally, a driver like this can rely mostly on the tty layer
+/*
+ * Normally, a driver like this can rely mostly on the tty layer
* locking, particularly when it comes to the driver structure.
* However, in this case, mconsole requests can come in "from the
* side", and race with opens and closes.
@@ -442,11 +434,11 @@ int line_open(struct line *lines, struct tty_struct *tty)
int err = -ENODEV;
spin_lock(&line->count_lock);
- if(!line->valid)
+ if (!line->valid)
goto out_unlock;
err = 0;
- if(tty->count > 1)
+ if (tty->count > 1)
goto out_unlock;
spin_unlock(&line->count_lock);
@@ -460,7 +452,7 @@ int line_open(struct line *lines, struct tty_struct *tty)
INIT_DELAYED_WORK(&line->task, line_timer_cb);
- if(!line->sigio){
+ if (!line->sigio) {
chan_enable_winch(&line->chan_list, tty);
line->sigio = 1;
}
@@ -481,20 +473,21 @@ void line_close(struct tty_struct *tty, struct file * filp)
{
struct line *line = tty->driver_data;
- /* If line_open fails (and tty->driver_data is never set),
+ /*
+ * If line_open fails (and tty->driver_data is never set),
* tty_open will call line_close. So just return in this case.
*/
- if(line == NULL)
+ if (line == NULL)
return;
/* We ignore the error anyway! */
flush_buffer(line);
spin_lock(&line->count_lock);
- if(!line->valid)
+ if (!line->valid)
goto out_unlock;
- if(tty->count > 1)
+ if (tty->count > 1)
goto out_unlock;
spin_unlock(&line->count_lock);
@@ -502,10 +495,10 @@ void line_close(struct tty_struct *tty, struct file * filp)
line->tty = NULL;
tty->driver_data = NULL;
- if(line->sigio){
+ if (line->sigio) {
unregister_winch(tty);
line->sigio = 0;
- }
+ }
return;
@@ -529,12 +522,12 @@ static int setup_one_line(struct line *lines, int n, char *init, int init_prio,
spin_lock(&line->count_lock);
- if(line->tty != NULL){
+ if (line->tty != NULL) {
*error_out = "Device is already open";
goto out;
}
- if (line->init_pri <= init_prio){
+ if (line->init_pri <= init_prio) {
line->init_pri = init_prio;
if (!strcmp(init, "none"))
line->valid = 0;
@@ -549,7 +542,8 @@ out:
return err;
}
-/* Common setup code for both startup command line and mconsole initialization.
+/*
+ * 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;
@@ -561,14 +555,16 @@ int line_setup(struct line *lines, unsigned int num, char *init,
int i, n, err;
char *end;
- if(*init == '=') {
- /* We said con=/ssl= instead of con#=, so we are configuring all
- * consoles at once.*/
+ if (*init == '=') {
+ /*
+ * We said con=/ssl= instead of con#=, so we are configuring all
+ * consoles at once.
+ */
n = -1;
}
else {
n = simple_strtoul(init, &end, 0);
- if(*end != '='){
+ if (*end != '=') {
*error_out = "Couldn't parse device number";
return -EINVAL;
}
@@ -580,16 +576,16 @@ int line_setup(struct line *lines, unsigned int num, char *init,
*error_out = "Device number out of range";
return -EINVAL;
}
- else if (n >= 0){
+ else if (n >= 0) {
err = setup_one_line(lines, n, init, INIT_ONE, error_out);
- if(err)
+ if (err)
return err;
}
else {
- for(i = 0; i < num; i++){
+ for(i = 0; i < num; i++) {
err = setup_one_line(lines, i, init, INIT_ALL,
error_out);
- if(err)
+ if (err)
return err;
}
}
@@ -603,18 +599,18 @@ int line_config(struct line *lines, unsigned int num, char *str,
char *new;
int n;
- if(*str == '='){
+ if (*str == '=') {
*error_out = "Can't configure all devices from mconsole";
return -EINVAL;
}
new = kstrdup(str, GFP_KERNEL);
- if(new == NULL){
+ if (new == NULL) {
*error_out = "Failed to allocate memory";
return -ENOMEM;
}
n = line_setup(lines, num, new, error_out);
- if(n < 0)
+ if (n < 0)
return n;
line = &lines[n];
@@ -629,12 +625,12 @@ int line_get_config(char *name, struct line *lines, unsigned int num, char *str,
int dev, n = 0;
dev = simple_strtoul(name, &end, 0);
- if((*end != '\0') || (end == name)){
+ if ((*end != '\0') || (end == name)) {
*error_out = "line_get_config failed to parse device number";
return 0;
}
- if((dev < 0) || (dev >= num)){
+ if ((dev < 0) || (dev >= num)) {
*error_out = "device number out of range";
return 0;
}
@@ -642,9 +638,9 @@ int line_get_config(char *name, struct line *lines, unsigned int num, char *str,
line = &lines[dev];
spin_lock(&line->count_lock);
- if(!line->valid)
+ if (!line->valid)
CONFIG_CHUNK(str, size, n, "none", 1);
- else if(line->tty == NULL)
+ else if (line->tty == NULL)
CONFIG_CHUNK(str, size, n, line->init_str, 1);
else n = chan_config_string(&line->chan_list, str, size, error_out);
spin_unlock(&line->count_lock);
@@ -655,16 +651,16 @@ int line_get_config(char *name, struct line *lines, unsigned int num, char *str,
int line_id(char **str, int *start_out, int *end_out)
{
char *end;
- int n;
+ int n;
n = simple_strtoul(*str, &end, 0);
- if((*end != '\0') || (end == *str))
- return -1;
+ if ((*end != '\0') || (end == *str))
+ return -1;
- *str = end;
- *start_out = n;
- *end_out = n;
- return n;
+ *str = end;
+ *start_out = n;
+ *end_out = n;
+ return n;
}
int line_remove(struct line *lines, unsigned int num, int n, char **error_out)
@@ -674,7 +670,7 @@ int line_remove(struct line *lines, unsigned int num, int n, char **error_out)
sprintf(config, "%d=none", n);
err = line_setup(lines, num, config, error_out);
- if(err >= 0)
+ if (err >= 0)
err = 0;
return err;
}
@@ -700,14 +696,14 @@ struct tty_driver *register_lines(struct line_driver *line_driver,
tty_set_operations(driver, ops);
if (tty_register_driver(driver)) {
- printk("%s: can't register %s driver\n",
- __FUNCTION__,line_driver->name);
+ printk(KERN_ERR "register_lines : can't register %s driver\n",
+ line_driver->name);
put_tty_driver(driver);
return NULL;
}
- for(i = 0; i < nlines; i++){
- if(!lines[i].valid)
+ for(i = 0; i < nlines; i++) {
+ if (!lines[i].valid)
tty_unregister_device(driver, i);
}
@@ -724,20 +720,20 @@ void lines_init(struct line *lines, int nlines, struct chan_opts *opts)
char *error;
int i;
- for(i = 0; i < nlines; i++){
+ for(i = 0; i < nlines; i++) {
line = &lines[i];
INIT_LIST_HEAD(&line->chan_list);
- if(line->init_str == NULL)
+ if (line->init_str == NULL)
continue;
line->init_str = kstrdup(line->init_str, GFP_KERNEL);
- if(line->init_str == NULL)
- printk("lines_init - kstrdup returned NULL\n");
+ if (line->init_str == NULL)
+ printk(KERN_ERR "lines_init - kstrdup returned NULL\n");
- if(parse_chan_pair(line->init_str, line, i, opts, &error)){
- printk("parse_chan_pair failed for device %d : %s\n",
- i, error);
+ if (parse_chan_pair(line->init_str, line, i, opts, &error)) {
+ printk(KERN_ERR "parse_chan_pair failed for "
+ "device %d : %s\n", i, error);
line->valid = 0;
}
}
@@ -775,14 +771,14 @@ static irqreturn_t winch_interrupt(int irq, void *data)
int err;
char c;
- if(winch->fd != -1){
+ if (winch->fd != -1) {
err = generic_read(winch->fd, &c, NULL);
- if(err < 0){
- if(err != -EAGAIN){
- printk("winch_interrupt : read failed, "
- "errno = %d\n", -err);
- printk("fd %d is losing SIGWINCH support\n",
- winch->tty_fd);
+ if (err < 0) {
+ if (err != -EAGAIN) {
+ printk(KERN_ERR "winch_interrupt : "
+ "read failed, errno = %d\n", -err);
+ printk(KERN_ERR "fd %d is losing SIGWINCH "
+ "support\n", winch->tty_fd);
free_winch(winch, 0);
return IRQ_HANDLED;
}
@@ -797,7 +793,7 @@ static irqreturn_t winch_interrupt(int irq, void *data)
kill_pgrp(tty->pgrp, SIGWINCH, 1);
}
out:
- if(winch->fd != -1)
+ if (winch->fd != -1)
reactivate_fd(winch->fd, WINCH_IRQ);
return IRQ_HANDLED;
}
@@ -809,7 +805,7 @@ void register_winch_irq(int fd, int tty_fd, int pid, struct tty_struct *tty,
winch = kmalloc(sizeof(*winch), GFP_KERNEL);
if (winch == NULL) {
- printk("register_winch_irq - kmalloc failed\n");
+ printk(KERN_ERR "register_winch_irq - kmalloc failed\n");
goto cleanup;
}
@@ -823,7 +819,8 @@ void register_winch_irq(int fd, int tty_fd, int pid, struct tty_struct *tty,
if (um_request_irq(WINCH_IRQ, fd, IRQ_READ, winch_interrupt,
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
"winch", winch) < 0) {
- printk("register_winch_irq - failed to register IRQ\n");
+ printk(KERN_ERR "register_winch_irq - failed to register "
+ "IRQ\n");
goto out_free;
}
@@ -849,13 +846,13 @@ static void unregister_winch(struct tty_struct *tty)
spin_lock(&winch_handler_lock);
- list_for_each(ele, &winch_handlers){
+ list_for_each(ele, &winch_handlers) {
winch = list_entry(ele, struct winch, list);
- if(winch->tty == tty){
+ if (winch->tty == tty) {
free_winch(winch, 1);
break;
- }
- }
+ }
+ }
spin_unlock(&winch_handler_lock);
}
@@ -866,7 +863,7 @@ static void winch_cleanup(void)
spin_lock(&winch_handler_lock);
- list_for_each_safe(ele, next, &winch_handlers){
+ list_for_each_safe(ele, next, &winch_handlers) {
winch = list_entry(ele, struct winch, list);
free_winch(winch, 1);
}
@@ -881,13 +878,13 @@ char *add_xterm_umid(char *base)
int len;
umid = get_umid();
- if(*umid == '\0')
+ if (*umid == '\0')
return base;
len = strlen(base) + strlen(" ()") + strlen(umid) + 1;
title = kmalloc(len, GFP_KERNEL);
- if(title == NULL){
- printk("Failed to allocate buffer for xterm title\n");
+ if (title == NULL) {
+ printk(KERN_ERR "Failed to allocate buffer for xterm title\n");
return base;
}
diff --git a/arch/um/drivers/mcast.h b/arch/um/drivers/mcast.h
index bc56af9d3e53..6fa282e896be 100644
--- a/arch/um/drivers/mcast.h
+++ b/arch/um/drivers/mcast.h
@@ -1,8 +1,11 @@
/*
- * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
+#ifndef __DRIVERS_MCAST_H
+#define __DRIVERS_MCAST_H
+
#include "net_user.h"
struct mcast_data {
@@ -18,13 +21,4 @@ extern const struct net_user_info mcast_user_info;
extern int mcast_user_write(int fd, void *buf, int len,
struct mcast_data *pri);
-/*
- * 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:
- */
+#endif
diff --git a/arch/um/drivers/mcast_kern.c b/arch/um/drivers/mcast_kern.c
index e6b8e0dd72a8..822092f149be 100644
--- a/arch/um/drivers/mcast_kern.c
+++ b/arch/um/drivers/mcast_kern.c
@@ -1,24 +1,20 @@
/*
* user-mode-linux networking multicast transport
* Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
*
* based on the existing uml-networking code, which is
- * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
+ * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 by various other people who didn't put their name here.
*
* Licensed under the GPL.
*/
-#include "linux/kernel.h"
#include "linux/init.h"
-#include "linux/netdevice.h"
-#include "linux/etherdevice.h"
-#include "linux/in.h"
-#include "linux/inet.h"
-#include "net_kern.h"
-#include "net_user.h"
+#include <linux/netdevice.h>
#include "mcast.h"
+#include "net_kern.h"
struct mcast_init {
char *addr;
@@ -39,26 +35,20 @@ static void mcast_init(struct net_device *dev, void *data)
dpri->ttl = init->ttl;
dpri->dev = dev;
- printk("mcast backend ");
- printk("multicast address: %s:%u, TTL:%u ",
+ printk("mcast backend multicast address: %s:%u, TTL:%u\n",
dpri->addr, dpri->port, dpri->ttl);
-
- printk("\n");
}
-static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
+static int mcast_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
- if(*skb == NULL) return(-ENOMEM);
- return(net_recvfrom(fd, skb_mac_header(*skb),
- (*skb)->dev->mtu + ETH_HEADER_OTHER));
+ return net_recvfrom(fd, skb_mac_header(skb),
+ skb->dev->mtu + ETH_HEADER_OTHER);
}
-static int mcast_write(int fd, struct sk_buff **skb,
- struct uml_net_private *lp)
+static int mcast_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- return mcast_user_write(fd, (*skb)->data, (*skb)->len,
- (struct mcast_data *) &lp->user);
+ return mcast_user_write(fd, skb->data, skb->len,
+ (struct mcast_data *) &lp->user);
}
static const struct net_kern_info mcast_kern_info = {
@@ -81,34 +71,34 @@ int mcast_setup(char *str, char **mac_out, void *data)
remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str,
NULL);
- if(remain != NULL){
+ if (remain != NULL) {
printk(KERN_ERR "mcast_setup - Extra garbage on "
"specification : '%s'\n", remain);
- return(0);
+ return 0;
}
-
- if(port_str != NULL){
+
+ if (port_str != NULL) {
init->port = simple_strtoul(port_str, &last, 10);
- if((*last != '\0') || (last == port_str)){
- printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
+ if ((*last != '\0') || (last == port_str)) {
+ printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
port_str);
- return(0);
+ return 0;
}
}
- if(ttl_str != NULL){
+ if (ttl_str != NULL) {
init->ttl = simple_strtoul(ttl_str, &last, 10);
- if((*last != '\0') || (last == ttl_str)){
- printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
+ if ((*last != '\0') || (last == ttl_str)) {
+ printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
ttl_str);
- return(0);
+ return 0;
}
}
printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr,
init->port, init->ttl);
- return(1);
+ return 1;
}
static struct transport mcast_transport = {
diff --git a/arch/um/drivers/mcast_user.c b/arch/um/drivers/mcast_user.c
index 236a3dfc297d..5f647d7a7292 100644
--- a/arch/um/drivers/mcast_user.c
+++ b/arch/um/drivers/mcast_user.c
@@ -1,9 +1,10 @@
/*
* user-mode-linux networking multicast transport
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
*
* based on the existing uml-networking code, which is
- * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
+ * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 by various other people who didn't put their name here.
*
@@ -11,28 +12,22 @@
*
*/
-#include <errno.h>
#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/time.h>
+#include <errno.h>
#include <netinet/in.h>
-#include "net_user.h"
#include "mcast.h"
-#include "kern_util.h"
-#include "user.h"
-#include "os.h"
+#include "net_user.h"
#include "um_malloc.h"
-
-#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
+#include "user.h"
static struct sockaddr_in *new_addr(char *addr, unsigned short port)
{
struct sockaddr_in *sin;
sin = kmalloc(sizeof(struct sockaddr_in), UM_GFP_KERNEL);
- if(sin == NULL){
- printk("new_addr: allocation of sockaddr_in failed\n");
+ if (sin == NULL) {
+ printk(UM_KERN_ERR "new_addr: allocation of sockaddr_in "
+ "failed\n");
return NULL;
}
sin->sin_family = AF_INET;
@@ -71,17 +66,17 @@ static int mcast_open(void *data)
fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (fd < 0){
+ if (fd < 0) {
err = -errno;
- printk("mcast_open : data socket failed, errno = %d\n",
- errno);
+ printk(UM_KERN_ERR "mcast_open : data socket failed, "
+ "errno = %d\n", errno);
goto out;
}
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
err = -errno;
- printk("mcast_open: SO_REUSEADDR failed, errno = %d\n",
- errno);
+ printk(UM_KERN_ERR "mcast_open: SO_REUSEADDR failed, "
+ "errno = %d\n", errno);
goto out_close;
}
@@ -89,45 +84,46 @@ static int mcast_open(void *data)
if (setsockopt(fd, SOL_IP, IP_MULTICAST_TTL, &pri->ttl,
sizeof(pri->ttl)) < 0) {
err = -errno;
- printk("mcast_open: IP_MULTICAST_TTL failed, error = %d\n",
- errno);
+ printk(UM_KERN_ERR "mcast_open: IP_MULTICAST_TTL failed, "
+ "error = %d\n", errno);
goto out_close;
}
/* set LOOP, so data does get fed back to local sockets */
if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
err = -errno;
- printk("mcast_open: IP_MULTICAST_LOOP failed, error = %d\n",
- errno);
+ printk(UM_KERN_ERR "mcast_open: IP_MULTICAST_LOOP failed, "
+ "error = %d\n", errno);
goto out_close;
}
/* bind socket to mcast address */
if (bind(fd, (struct sockaddr *) sin, sizeof(*sin)) < 0) {
err = -errno;
- printk("mcast_open : data bind failed, errno = %d\n", errno);
+ printk(UM_KERN_ERR "mcast_open : data bind failed, "
+ "errno = %d\n", errno);
goto out_close;
}
/* subscribe to the multicast group */
mreq.imr_multiaddr.s_addr = sin->sin_addr.s_addr;
mreq.imr_interface.s_addr = 0;
- if (setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP,
+ if (setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP,
&mreq, sizeof(mreq)) < 0) {
err = -errno;
- printk("mcast_open: IP_ADD_MEMBERSHIP failed, error = %d\n",
- errno);
- printk("There appears not to be a multicast-capable network "
- "interface on the host.\n");
- printk("eth0 should be configured in order to use the "
- "multicast transport.\n");
+ printk(UM_KERN_ERR "mcast_open: IP_ADD_MEMBERSHIP failed, "
+ "error = %d\n", errno);
+ printk(UM_KERN_ERR "There appears not to be a multicast-"
+ "capable network interface on the host.\n");
+ printk(UM_KERN_ERR "eth0 should be configured in order to use "
+ "the multicast transport.\n");
goto out_close;
}
return fd;
out_close:
- os_close_file(fd);
+ close(fd);
out:
return err;
}
@@ -142,11 +138,11 @@ static void mcast_close(int fd, void *data)
mreq.imr_interface.s_addr = 0;
if (setsockopt(fd, SOL_IP, IP_DROP_MEMBERSHIP,
&mreq, sizeof(mreq)) < 0) {
- printk("mcast_open: IP_DROP_MEMBERSHIP failed, error = %d\n",
- errno);
+ printk(UM_KERN_ERR "mcast_open: IP_DROP_MEMBERSHIP failed, "
+ "error = %d\n", errno);
}
- os_close_file(fd);
+ close(fd);
}
int mcast_user_write(int fd, void *buf, int len, struct mcast_data *pri)
@@ -156,18 +152,13 @@ int mcast_user_write(int fd, void *buf, int len, struct mcast_data *pri)
return net_sendto(fd, buf, len, data_addr, sizeof(*data_addr));
}
-static int mcast_set_mtu(int mtu, void *data)
-{
- return mtu;
-}
-
const struct net_user_info mcast_user_info = {
.init = mcast_user_init,
.open = mcast_open,
.close = mcast_close,
.remove = mcast_remove,
- .set_mtu = mcast_set_mtu,
.add_address = NULL,
.delete_address = NULL,
- .max_packet = MAX_PACKET - ETH_HEADER_OTHER
+ .mtu = ETH_MAX_PACKET,
+ .max_packet = ETH_MAX_PACKET + ETH_HEADER_OTHER,
};
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index d87090507401..0f3c7d14a6e3 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -1,44 +1,35 @@
/*
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
- * Copyright (C) 2001 - 2003 Jeff Dike (jdike@addtoit.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
-#include "linux/kernel.h"
-#include "linux/slab.h"
-#include "linux/init.h"
-#include "linux/notifier.h"
-#include "linux/reboot.h"
-#include "linux/utsname.h"
+#include "linux/console.h"
#include "linux/ctype.h"
#include "linux/interrupt.h"
-#include "linux/sysrq.h"
-#include "linux/workqueue.h"
+#include "linux/list.h"
+#include "linux/mm.h"
#include "linux/module.h"
-#include "linux/file.h"
-#include "linux/fs.h"
-#include "linux/namei.h"
+#include "linux/notifier.h"
+#include "linux/reboot.h"
#include "linux/proc_fs.h"
+#include "linux/slab.h"
#include "linux/syscalls.h"
-#include "linux/list.h"
-#include "linux/mm.h"
-#include "linux/console.h"
-#include "asm/irq.h"
+#include "linux/utsname.h"
+#include "linux/workqueue.h"
#include "asm/uaccess.h"
+#include "init.h"
+#include "irq_kern.h"
+#include "irq_user.h"
#include "kern_util.h"
-#include "kern.h"
#include "mconsole.h"
#include "mconsole_kern.h"
-#include "irq_user.h"
-#include "init.h"
#include "os.h"
-#include "irq_kern.h"
-#include "choose-mode.h"
static int do_unlink_socket(struct notifier_block *notifier,
unsigned long what, void *data)
{
- return(mconsole_unlink_socket());
+ return mconsole_unlink_socket();
}
@@ -59,10 +50,9 @@ static void mc_work_proc(struct work_struct *unused)
struct mconsole_entry *req;
unsigned long flags;
- while(!list_empty(&mc_requests)){
+ while (!list_empty(&mc_requests)) {
local_irq_save(flags);
- req = list_entry(mc_requests.next, struct mconsole_entry,
- list);
+ req = list_entry(mc_requests.next, struct mconsole_entry, list);
list_del(&req->list);
local_irq_restore(flags);
req->request.cmd->handler(&req->request);
@@ -80,12 +70,12 @@ static irqreturn_t mconsole_interrupt(int irq, void *dev_id)
static struct mc_request req; /* that's OK */
fd = (long) dev_id;
- while (mconsole_get_request(fd, &req)){
- if(req.cmd->context == MCONSOLE_INTR)
+ while (mconsole_get_request(fd, &req)) {
+ if (req.cmd->context == MCONSOLE_INTR)
(*req.cmd->handler)(&req);
else {
new = kmalloc(sizeof(*new), GFP_NOWAIT);
- if(new == NULL)
+ if (new == NULL)
mconsole_reply(&req, "Out of memory", 1, 0);
else {
new->request = req;
@@ -94,10 +84,10 @@ static irqreturn_t mconsole_interrupt(int irq, void *dev_id)
}
}
}
- if(!list_empty(&mc_requests))
+ if (!list_empty(&mc_requests))
schedule_work(&mconsole_work);
reactivate_fd(fd, MCONSOLE_IRQ);
- return(IRQ_HANDLED);
+ return IRQ_HANDLED;
}
void mconsole_version(struct mc_request *req)
@@ -105,8 +95,8 @@ void mconsole_version(struct mc_request *req)
char version[256];
sprintf(version, "%s %s %s %s %s", utsname()->sysname,
- utsname()->nodename, utsname()->release,
- utsname()->version, utsname()->machine);
+ utsname()->nodename, utsname()->release, utsname()->version,
+ utsname()->machine);
mconsole_reply(req, version, 0, 0);
}
@@ -118,7 +108,7 @@ void mconsole_log(struct mc_request *req)
ptr += strlen("log ");
len = req->len - (ptr - req->request.data);
- printk("%.*s", len, ptr);
+ printk(KERN_WARNING "%.*s", len, ptr);
mconsole_reply(req, "", 0, 0);
}
@@ -137,17 +127,17 @@ void mconsole_proc(struct mc_request *req)
char *ptr = req->request.data, *buf;
ptr += strlen("proc");
- while(isspace(*ptr)) ptr++;
+ while (isspace(*ptr)) ptr++;
proc = get_fs_type("proc");
- if(proc == NULL){
+ if (proc == NULL) {
mconsole_reply(req, "procfs not registered", 1, 0);
goto out;
}
super = (*proc->get_sb)(proc, 0, NULL, NULL);
put_filesystem(proc);
- if(super == NULL){
+ if (super == NULL) {
mconsole_reply(req, "Failed to get procfs superblock", 1, 0);
goto out;
}
@@ -162,29 +152,29 @@ void mconsole_proc(struct mc_request *req)
* if commenting out these two calls + the below read cycle. To
* make UML crash again, it was enough to readd either one.*/
err = link_path_walk(ptr, &nd);
- if(err){
+ if (err) {
mconsole_reply(req, "Failed to look up file", 1, 0);
goto out_kill;
}
file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
- if(IS_ERR(file)){
+ if (IS_ERR(file)) {
mconsole_reply(req, "Failed to open file", 1, 0);
goto out_kill;
}
/*END*/
buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
- if(buf == NULL){
+ if (buf == NULL) {
mconsole_reply(req, "Failed to allocate buffer", 1, 0);
goto out_fput;
}
- if((file->f_op != NULL) && (file->f_op->read != NULL)){
+ if ((file->f_op != NULL) && (file->f_op->read != NULL)) {
do {
n = (*file->f_op->read)(file, buf, PAGE_SIZE - 1,
&file->f_pos);
- if(n >= 0){
+ if (n >= 0) {
buf[n] = '\0';
mconsole_reply(req, buf, 0, (n > 0));
}
@@ -193,7 +183,7 @@ void mconsole_proc(struct mc_request *req)
1, 0);
goto out_free;
}
- } while(n > 0);
+ } while (n > 0);
}
else mconsole_reply(req, "", 0, 0);
@@ -217,18 +207,19 @@ void mconsole_proc(struct mc_request *req)
char *ptr = req->request.data;
ptr += strlen("proc");
- while(isspace(*ptr)) ptr++;
+ while (isspace(*ptr))
+ ptr++;
snprintf(path, sizeof(path), "/proc/%s", ptr);
fd = sys_open(path, 0, 0);
if (fd < 0) {
mconsole_reply(req, "Failed to open file", 1, 0);
- printk("open %s: %d\n",path,fd);
+ printk(KERN_ERR "open %s: %d\n",path,fd);
goto out;
}
buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
- if(buf == NULL){
+ if (buf == NULL) {
mconsole_reply(req, "Failed to allocate buffer", 1, 0);
goto out_close;
}
@@ -239,7 +230,7 @@ void mconsole_proc(struct mc_request *req)
mconsole_reply(req, "Read of file failed", 1, 0);
goto out_free;
}
- /*Begin the file content on his own line.*/
+ /* Begin the file content on his own line. */
if (first_chunk) {
mconsole_reply(req, "\n", 0, 1);
first_chunk = 0;
@@ -351,12 +342,12 @@ static struct mc_device *mconsole_find_dev(char *name)
struct list_head *ele;
struct mc_device *dev;
- list_for_each(ele, &mconsole_devices){
+ list_for_each(ele, &mconsole_devices) {
dev = list_entry(ele, struct mc_device, list);
- if(!strncmp(name, dev->name, strlen(dev->name)))
- return(dev);
+ if (!strncmp(name, dev->name, strlen(dev->name)))
+ return dev;
}
- return(NULL);
+ return NULL;
}
#define UNPLUGGED_PER_PAGE \
@@ -378,15 +369,15 @@ static int mem_config(char *str, char **error_out)
int err = -EINVAL, i, add;
char *ret;
- if(str[0] != '='){
+ if (str[0] != '=') {
*error_out = "Expected '=' after 'mem'";
goto out;
}
str++;
- if(str[0] == '-')
+ if (str[0] == '-')
add = 0;
- else if(str[0] == '+'){
+ else if (str[0] == '+') {
add = 1;
}
else {
@@ -396,7 +387,7 @@ static int mem_config(char *str, char **error_out)
str++;
diff = memparse(str, &ret);
- if(*ret != '\0'){
+ if (*ret != '\0') {
*error_out = "Failed to parse memory increment";
goto out;
}
@@ -404,17 +395,17 @@ static int mem_config(char *str, char **error_out)
diff /= PAGE_SIZE;
down(&plug_mem_mutex);
- for(i = 0; i < diff; i++){
+ for (i = 0; i < diff; i++) {
struct unplugged_pages *unplugged;
void *addr;
- if(add){
- if(list_empty(&unplugged_pages))
+ if (add) {
+ if (list_empty(&unplugged_pages))
break;
unplugged = list_entry(unplugged_pages.next,
struct unplugged_pages, list);
- if(unplug_index > 0)
+ if (unplug_index > 0)
addr = unplugged->pages[--unplug_index];
else {
list_del(&unplugged->list);
@@ -429,11 +420,11 @@ static int mem_config(char *str, char **error_out)
struct page *page;
page = alloc_page(GFP_ATOMIC);
- if(page == NULL)
+ if (page == NULL)
break;
unplugged = page_address(page);
- if(unplug_index == UNPLUGGED_PER_PAGE){
+ if (unplug_index == UNPLUGGED_PER_PAGE) {
list_add(&unplugged->list, &unplugged_pages);
unplug_index = 0;
}
@@ -445,9 +436,9 @@ static int mem_config(char *str, char **error_out)
struct unplugged_pages,
list);
err = os_drop_memory(addr, PAGE_SIZE);
- if(err){
- printk("Failed to release memory - "
- "errno = %d\n", err);
+ if (err) {
+ printk(KERN_ERR "Failed to release "
+ "memory - errno = %d\n", err);
*error_out = "Failed to release memory";
goto out_unlock;
}
@@ -501,10 +492,10 @@ static struct mc_device mem_mc = {
static int __init mem_mc_init(void)
{
- if(can_drop_memory())
+ if (can_drop_memory())
mconsole_register_dev(&mem_mc);
- else printk("Can't release memory to the host - memory hotplug won't "
- "be supported\n");
+ else printk(KERN_ERR "Can't release memory to the host - memory "
+ "hotplug won't be supported\n");
return 0;
}
@@ -519,7 +510,7 @@ static void mconsole_get_config(int (*get_config)(char *, char *, int,
char default_buf[CONFIG_BUF_SIZE], *error, *buf;
int n, size;
- if(get_config == NULL){
+ if (get_config == NULL) {
mconsole_reply(req, "No get_config routine defined", 1, 0);
return;
}
@@ -528,30 +519,30 @@ static void mconsole_get_config(int (*get_config)(char *, char *, int,
size = ARRAY_SIZE(default_buf);
buf = default_buf;
- while(1){
+ while (1) {
n = (*get_config)(name, buf, size, &error);
- if(error != NULL){
+ if (error != NULL) {
mconsole_reply(req, error, 1, 0);
goto out;
}
- if(n <= size){
+ if (n <= size) {
mconsole_reply(req, buf, 0, 0);
goto out;
}
- if(buf != default_buf)
+ if (buf != default_buf)
kfree(buf);
size = n;
buf = kmalloc(size, GFP_KERNEL);
- if(buf == NULL){
+ if (buf == NULL) {
mconsole_reply(req, "Failed to allocate buffer", 1, 0);
return;
}
}
out:
- if(buf != default_buf)
+ if (buf != default_buf)
kfree(buf);
}
@@ -562,19 +553,20 @@ void mconsole_config(struct mc_request *req)
int err;
ptr += strlen("config");
- while(isspace(*ptr)) ptr++;
+ while (isspace(*ptr))
+ ptr++;
dev = mconsole_find_dev(ptr);
- if(dev == NULL){
+ if (dev == NULL) {
mconsole_reply(req, "Bad configuration option", 1, 0);
return;
}
name = &ptr[strlen(dev->name)];
ptr = name;
- while((*ptr != '=') && (*ptr != '\0'))
+ while ((*ptr != '=') && (*ptr != '\0'))
ptr++;
- if(*ptr == '='){
+ if (*ptr == '=') {
err = (*dev->config)(name, &error_string);
mconsole_reply(req, error_string, err, 0);
}
@@ -589,9 +581,9 @@ void mconsole_remove(struct mc_request *req)
int err, start, end, n;
ptr += strlen("remove");
- while(isspace(*ptr)) ptr++;
+ while (isspace(*ptr)) ptr++;
dev = mconsole_find_dev(ptr);
- if(dev == NULL){
+ if (dev == NULL) {
mconsole_reply(req, "Bad remove option", 1, 0);
return;
}
@@ -600,11 +592,11 @@ void mconsole_remove(struct mc_request *req)
err = 1;
n = (*dev->id)(&ptr, &start, &end);
- if(n < 0){
+ if (n < 0) {
err_msg = "Couldn't parse device number";
goto out;
}
- else if((n < start) || (n > end)){
+ else if ((n < start) || (n > end)) {
sprintf(error, "Invalid device number - must be between "
"%d and %d", start, end);
err_msg = error;
@@ -613,16 +605,16 @@ void mconsole_remove(struct mc_request *req)
err_msg = NULL;
err = (*dev->remove)(n, &err_msg);
- switch(err){
+ switch(err) {
case 0:
err_msg = "";
break;
case -ENODEV:
- if(err_msg == NULL)
+ if (err_msg == NULL)
err_msg = "Device doesn't exist";
break;
case -EBUSY:
- if(err_msg == NULL)
+ if (err_msg == NULL)
err_msg = "Device is currently open";
break;
default:
@@ -640,35 +632,28 @@ struct mconsole_output {
static DEFINE_SPINLOCK(client_lock);
static LIST_HEAD(clients);
static char console_buf[MCONSOLE_MAX_DATA];
-static int console_index = 0;
static void console_write(struct console *console, const char *string,
- unsigned len)
+ unsigned int len)
{
struct list_head *ele;
int n;
- if(list_empty(&clients))
+ if (list_empty(&clients))
return;
- while(1){
- n = min((size_t) len, ARRAY_SIZE(console_buf) - console_index);
- strncpy(&console_buf[console_index], string, n);
- console_index += n;
+ while (len > 0) {
+ n = min((size_t) len, ARRAY_SIZE(console_buf));
+ strncpy(console_buf, string, n);
string += n;
len -= n;
- if(len == 0)
- return;
- list_for_each(ele, &clients){
+ list_for_each(ele, &clients) {
struct mconsole_output *entry;
entry = list_entry(ele, struct mconsole_output, list);
- mconsole_reply_len(entry->req, console_buf,
- console_index, 0, 1);
+ mconsole_reply_len(entry->req, console_buf, n, 0, 1);
}
-
- console_index = 0;
}
}
@@ -698,8 +683,7 @@ static void with_console(struct mc_request *req, void (*proc)(void *),
(*proc)(arg);
- mconsole_reply_len(req, console_buf, console_index, 0, 0);
- console_index = 0;
+ mconsole_reply_len(req, "", 0, 0, 0);
spin_lock_irqsave(&client_lock, flags);
list_del(&entry.list);
@@ -707,6 +691,9 @@ static void with_console(struct mc_request *req, void (*proc)(void *),
}
#ifdef CONFIG_MAGIC_SYSRQ
+
+#include <linux/sysrq.h>
+
static void sysrq_proc(void *arg)
{
char *op = arg;
@@ -718,12 +705,13 @@ void mconsole_sysrq(struct mc_request *req)
char *ptr = req->request.data;
ptr += strlen("sysrq");
- while(isspace(*ptr)) ptr++;
+ while (isspace(*ptr)) ptr++;
- /* With 'b', the system will shut down without a chance to reply,
+ /*
+ * With 'b', the system will shut down without a chance to reply,
* so in this case, we reply first.
*/
- if(*ptr == 'b')
+ if (*ptr == 'b')
mconsole_reply(req, "", 0, 0);
with_console(req, sysrq_proc, ptr);
@@ -735,8 +723,6 @@ void mconsole_sysrq(struct mc_request *req)
}
#endif
-#ifdef CONFIG_MODE_SKAS
-
static void stack_proc(void *arg)
{
struct task_struct *from = current, *to = arg;
@@ -745,29 +731,34 @@ static void stack_proc(void *arg)
switch_to(from, to, from);
}
-/* Mconsole stack trace
+/*
+ * Mconsole stack trace
* Added by Allan Graves, Jeff Dike
* Dumps a stacks registers to the linux console.
* Usage stack <pid>.
*/
-static void do_stack_trace(struct mc_request *req)
+void mconsole_stack(struct mc_request *req)
{
char *ptr = req->request.data;
int pid_requested= -1;
struct task_struct *from = NULL;
struct task_struct *to = NULL;
- /* Would be nice:
+ /*
+ * Would be nice:
* 1) Send showregs output to mconsole.
* 2) Add a way to stack dump all pids.
*/
ptr += strlen("stack");
- while(isspace(*ptr)) ptr++;
+ while (isspace(*ptr))
+ ptr++;
- /* Should really check for multiple pids or reject bad args here */
+ /*
+ * Should really check for multiple pids or reject bad args here
+ */
/* What do the arguments in mconsole_reply mean? */
- if(sscanf(ptr, "%d", &pid_requested) == 0){
+ if (sscanf(ptr, "%d", &pid_requested) == 0) {
mconsole_reply(req, "Please specify a pid", 1, 0);
return;
}
@@ -775,25 +766,15 @@ static void do_stack_trace(struct mc_request *req)
from = current;
to = find_task_by_pid(pid_requested);
- if((to == NULL) || (pid_requested == 0)) {
+ if ((to == NULL) || (pid_requested == 0)) {
mconsole_reply(req, "Couldn't find that pid", 1, 0);
return;
}
with_console(req, stack_proc, to);
}
-#endif /* CONFIG_MODE_SKAS */
-void mconsole_stack(struct mc_request *req)
-{
- /* This command doesn't work in TT mode, so let's check and then
- * get out of here
- */
- CHOOSE_MODE(mconsole_reply(req, "Sorry, this doesn't work in TT mode",
- 1, 0),
- do_stack_trace(req));
-}
-
-/* Changed by mconsole_setup, which is __setup, and called before SMP is
+/*
+ * Changed by mconsole_setup, which is __setup, and called before SMP is
* active.
*/
static char *notify_socket = NULL;
@@ -805,13 +786,14 @@ static int __init mconsole_init(void)
int err;
char file[256];
- if(umid_file_name("mconsole", file, sizeof(file))) return(-1);
+ if (umid_file_name("mconsole", file, sizeof(file)))
+ return -1;
snprintf(mconsole_socket_name, sizeof(file), "%s", file);
sock = os_create_unix_socket(file, sizeof(file), 1);
- if (sock < 0){
- printk("Failed to initialize management console\n");
- return(1);
+ if (sock < 0) {
+ printk(KERN_ERR "Failed to initialize management console\n");
+ return 1;
}
register_reboot_notifier(&reboot_notifier);
@@ -819,14 +801,14 @@ static int __init mconsole_init(void)
err = um_request_irq(MCONSOLE_IRQ, sock, IRQ_READ, mconsole_interrupt,
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
"mconsole", (void *)sock);
- if (err){
- printk("Failed to get IRQ for management console\n");
- return(1);
+ if (err) {
+ printk(KERN_ERR "Failed to get IRQ for management console\n");
+ return 1;
}
- if(notify_socket != NULL){
+ if (notify_socket != NULL) {
notify_socket = kstrdup(notify_socket, GFP_KERNEL);
- if(notify_socket != NULL)
+ if (notify_socket != NULL)
mconsole_notify(notify_socket, MCONSOLE_SOCKET,
mconsole_socket_name,
strlen(mconsole_socket_name) + 1);
@@ -834,9 +816,9 @@ static int __init mconsole_init(void)
"string\n");
}
- printk("mconsole (version %d) initialized on %s\n",
+ printk(KERN_INFO "mconsole (version %d) initialized on %s\n",
MCONSOLE_VERSION, mconsole_socket_name);
- return(0);
+ return 0;
}
__initcall(mconsole_init);
@@ -847,10 +829,10 @@ static int write_proc_mconsole(struct file *file, const char __user *buffer,
char *buf;
buf = kmalloc(count + 1, GFP_KERNEL);
- if(buf == NULL)
- return(-ENOMEM);
+ if (buf == NULL)
+ return -ENOMEM;
- if(copy_from_user(buf, buffer, count)){
+ if (copy_from_user(buf, buffer, count)) {
count = -EFAULT;
goto out;
}
@@ -860,24 +842,26 @@ static int write_proc_mconsole(struct file *file, const char __user *buffer,
mconsole_notify(notify_socket, MCONSOLE_USER_NOTIFY, buf, count);
out:
kfree(buf);
- return(count);
+ return count;
}
static int create_proc_mconsole(void)
{
struct proc_dir_entry *ent;
- if(notify_socket == NULL) return(0);
+ if (notify_socket == NULL)
+ return 0;
ent = create_proc_entry("mconsole", S_IFREG | 0200, NULL);
- if(ent == NULL){
- printk(KERN_INFO "create_proc_mconsole : create_proc_entry failed\n");
- return(0);
+ if (ent == NULL) {
+ printk(KERN_INFO "create_proc_mconsole : create_proc_entry "
+ "failed\n");
+ return 0;
}
ent->read_proc = NULL;
ent->write_proc = write_proc_mconsole;
- return(0);
+ return 0;
}
static DEFINE_SPINLOCK(notify_spinlock);
@@ -894,19 +878,19 @@ void unlock_notify(void)
__initcall(create_proc_mconsole);
-#define NOTIFY "=notify:"
+#define NOTIFY "notify:"
static int mconsole_setup(char *str)
{
- if(!strncmp(str, NOTIFY, strlen(NOTIFY))){
+ if (!strncmp(str, NOTIFY, strlen(NOTIFY))) {
str += strlen(NOTIFY);
notify_socket = str;
}
else printk(KERN_ERR "mconsole_setup : Unknown option - '%s'\n", str);
- return(1);
+ return 1;
}
-__setup("mconsole", mconsole_setup);
+__setup("mconsole=", mconsole_setup);
__uml_help(mconsole_setup,
"mconsole=notify:<socket>\n"
@@ -921,11 +905,12 @@ static int notify_panic(struct notifier_block *self, unsigned long unused1,
{
char *message = ptr;
- if(notify_socket == NULL) return(0);
+ if (notify_socket == NULL)
+ return 0;
mconsole_notify(notify_socket, MCONSOLE_PANIC, message,
strlen(message) + 1);
- return(0);
+ return 0;
}
static struct notifier_block panic_exit_notifier = {
@@ -938,14 +923,14 @@ static int add_notifier(void)
{
atomic_notifier_chain_register(&panic_notifier_list,
&panic_exit_notifier);
- return(0);
+ return 0;
}
__initcall(add_notifier);
char *mconsole_notify_socket(void)
{
- return(notify_socket);
+ return notify_socket;
}
EXPORT_SYMBOL(mconsole_notify_socket);
diff --git a/arch/um/drivers/mconsole_user.c b/arch/um/drivers/mconsole_user.c
index f31e71546e52..430c024a19b0 100644
--- a/arch/um/drivers/mconsole_user.c
+++ b/arch/um/drivers/mconsole_user.c
@@ -1,25 +1,22 @@
/*
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
- * Copyright (C) 2001 - 2003 Jeff Dike (jdike@addtoit.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
-#include <stdio.h>
-#include <stdlib.h>
#include <errno.h>
-#include <signal.h>
+#include <string.h>
+#include <unistd.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <sys/uio.h>
#include <sys/un.h>
-#include <unistd.h>
-#include "user.h"
-#include "sysdep/ptrace.h"
+#include "kern_constants.h"
#include "mconsole.h"
-#include "os.h"
+#include "user.h"
static struct mconsole_command commands[] = {
- /* With uts namespaces, uts information becomes process-specific, so
+ /*
+ * With uts namespaces, uts information becomes process-specific, so
* we need a process context. If we try handling this in interrupt
* context, we may hit an exiting process without a valid uts
* namespace.
@@ -36,7 +33,7 @@ static struct mconsole_command commands[] = {
{ "go", mconsole_go, MCONSOLE_INTR },
{ "log", mconsole_log, MCONSOLE_INTR },
{ "proc", mconsole_proc, MCONSOLE_PROC },
- { "stack", mconsole_stack, MCONSOLE_INTR },
+ { "stack", mconsole_stack, MCONSOLE_INTR },
};
/* Initialized in mconsole_init, which is an initcall */
@@ -44,21 +41,21 @@ char mconsole_socket_name[256];
int mconsole_reply_v0(struct mc_request *req, char *reply)
{
- struct iovec iov;
- struct msghdr msg;
+ struct iovec iov;
+ struct msghdr msg;
- iov.iov_base = reply;
- iov.iov_len = strlen(reply);
+ iov.iov_base = reply;
+ iov.iov_len = strlen(reply);
- msg.msg_name = &(req->origin);
- msg.msg_namelen = req->originlen;
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
- msg.msg_flags = 0;
+ msg.msg_name = &(req->origin);
+ msg.msg_namelen = req->originlen;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ msg.msg_flags = 0;
- return sendmsg(req->originating_fd, &msg, 0);
+ return sendmsg(req->originating_fd, &msg, 0);
}
static struct mconsole_command *mconsole_parse(struct mc_request *req)
@@ -66,10 +63,10 @@ static struct mconsole_command *mconsole_parse(struct mc_request *req)
struct mconsole_command *cmd;
int i;
- for(i = 0; i < ARRAY_SIZE(commands); i++){
+ for (i = 0; i < ARRAY_SIZE(commands); i++) {
cmd = &commands[i];
- if(!strncmp(req->request.data, cmd->command,
- strlen(cmd->command))){
+ if (!strncmp(req->request.data, cmd->command,
+ strlen(cmd->command))) {
return cmd;
}
}
@@ -94,9 +91,9 @@ int mconsole_get_request(int fd, struct mc_request *req)
req->originating_fd = fd;
- if(req->request.magic != MCONSOLE_MAGIC){
+ if (req->request.magic != MCONSOLE_MAGIC) {
/* Unversioned request */
- len = MIN(sizeof(req->request.data) - 1,
+ len = MIN(sizeof(req->request.data) - 1,
strlen((char *) &req->request));
memmove(req->request.data, &req->request, len);
req->request.data[len] = '\0';
@@ -107,32 +104,33 @@ int mconsole_get_request(int fd, struct mc_request *req)
mconsole_reply_v0(req, "ERR Version 0 mconsole clients are "
"not supported by this driver");
- return(0);
+ return 0;
}
- if(req->request.len >= MCONSOLE_MAX_DATA){
+ if (req->request.len >= MCONSOLE_MAX_DATA) {
mconsole_reply(req, "Request too large", 1, 0);
- return(0);
+ return 0;
}
- if(req->request.version != MCONSOLE_VERSION){
- mconsole_reply(req, "This driver only supports version "
- STRING(MCONSOLE_VERSION) " clients", 1, 0);
+ if (req->request.version != MCONSOLE_VERSION) {
+ mconsole_reply(req, "This driver only supports version "
+ STRING(MCONSOLE_VERSION) " clients", 1, 0);
}
-
+
req->request.data[req->request.len] = '\0';
req->cmd = mconsole_parse(req);
- if(req->cmd == NULL){
+ if (req->cmd == NULL) {
mconsole_reply(req, "Unknown command", 1, 0);
- return(0);
+ return 0;
}
- return(1);
+ return 1;
}
int mconsole_reply_len(struct mc_request *req, const char *str, int total,
int err, int more)
{
- /* XXX This is a stack consumption problem. It'd be nice to
+ /*
+ * XXX This is a stack consumption problem. It'd be nice to
* make it global and serialize access to it, but there are a
* ton of callers to this function.
*/
@@ -147,7 +145,7 @@ int mconsole_reply_len(struct mc_request *req, const char *str, int total,
len = MIN(total, MCONSOLE_MAX_DATA - 1);
- if(len == total) reply.more = more;
+ if (len == total) reply.more = more;
else reply.more = 1;
memcpy(reply.data, str, len);
@@ -161,9 +159,10 @@ int mconsole_reply_len(struct mc_request *req, const char *str, int total,
n = sendto(req->originating_fd, &reply, len, 0,
(struct sockaddr *) req->origin, req->originlen);
- if(n < 0) return(-errno);
- } while(total > 0);
- return(0);
+ if (n < 0)
+ return -errno;
+ } while (total > 0);
+ return 0;
}
int mconsole_reply(struct mc_request *req, const char *str, int err, int more)
@@ -187,18 +186,18 @@ int mconsole_notify(char *sock_name, int type, const void *data, int len)
int n, err = 0;
lock_notify();
- if(notify_sock < 0){
+ if (notify_sock < 0) {
notify_sock = socket(PF_UNIX, SOCK_DGRAM, 0);
- if(notify_sock < 0){
+ if (notify_sock < 0) {
err = -errno;
- printk("mconsole_notify - socket failed, errno = %d\n",
- err);
+ printk(UM_KERN_ERR "mconsole_notify - socket failed, "
+ "errno = %d\n", errno);
}
}
unlock_notify();
-
- if(err)
- return(err);
+
+ if (err)
+ return err;
target.sun_family = AF_UNIX;
strcpy(target.sun_path, sock_name);
@@ -212,22 +211,12 @@ int mconsole_notify(char *sock_name, int type, const void *data, int len)
err = 0;
len = sizeof(packet) + packet.len - sizeof(packet.data);
- n = sendto(notify_sock, &packet, len, 0, (struct sockaddr *) &target,
+ n = sendto(notify_sock, &packet, len, 0, (struct sockaddr *) &target,
sizeof(target));
- if(n < 0){
+ if (n < 0) {
err = -errno;
- printk("mconsole_notify - sendto failed, errno = %d\n", errno);
+ printk(UM_KERN_ERR "mconsole_notify - sendto failed, "
+ "errno = %d\n", errno);
}
- return(err);
+ return err;
}
-
-/*
- * 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:
- */
diff --git a/arch/um/drivers/mmapper_kern.c b/arch/um/drivers/mmapper_kern.c
index 867666a02339..67b2f55a602f 100644
--- a/arch/um/drivers/mmapper_kern.c
+++ b/arch/um/drivers/mmapper_kern.c
@@ -9,27 +9,29 @@
*
*/
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/mm.h>
+#include <linux/stddef.h>
+#include <linux/types.h>
#include <linux/fs.h>
+#include <linux/init.h>
#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/mm.h>
#include <asm/uaccess.h>
#include "mem_user.h"
-
+
/* These are set in mmapper_init, which is called at boot time */
static unsigned long mmapper_size;
-static unsigned long p_buf = 0;
-static char *v_buf = NULL;
+static unsigned long p_buf;
+static char *v_buf;
-static ssize_t
-mmapper_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t mmapper_read(struct file *file, char __user *buf, size_t count,
+ loff_t *ppos)
{
return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
}
-static ssize_t
-mmapper_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
+static ssize_t mmapper_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
{
if (*ppos > mmapper_size)
return -EINVAL;
@@ -39,48 +41,46 @@ mmapper_write(struct file *file, const char __user *buf, size_t count, loff_t *p
if (copy_from_user(&v_buf[*ppos], buf, count))
return -EFAULT;
-
+
return count;
}
-static int
-mmapper_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
- unsigned long arg)
+static int mmapper_ioctl(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
{
- return(-ENOIOCTLCMD);
+ return -ENOIOCTLCMD;
}
-static int
-mmapper_mmap(struct file *file, struct vm_area_struct * vma)
+static int mmapper_mmap(struct file *file, struct vm_area_struct *vma)
{
int ret = -EINVAL;
int size;
if (vma->vm_pgoff != 0)
goto out;
-
+
size = vma->vm_end - vma->vm_start;
- if(size > mmapper_size) return(-EFAULT);
+ if (size > mmapper_size)
+ return -EFAULT;
- /* XXX A comment above remap_pfn_range says it should only be
+ /*
+ * XXX A comment above remap_pfn_range says it should only be
* called when the mm semaphore is held
*/
if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
- vma->vm_page_prot))
+ vma->vm_page_prot))
goto out;
ret = 0;
out:
return ret;
}
-static int
-mmapper_open(struct inode *inode, struct file *file)
+static int mmapper_open(struct inode *inode, struct file *file)
{
return 0;
}
-static int
-mmapper_release(struct inode *inode, struct file *file)
+static int mmapper_release(struct inode *inode, struct file *file)
{
return 0;
}
@@ -95,7 +95,9 @@ static const struct file_operations mmapper_fops = {
.release = mmapper_release,
};
-/* No locking needed - only used (and modified) by below initcall and exitcall. */
+/*
+ * No locking needed - only used (and modified) by below initcall and exitcall.
+ */
static struct miscdevice mmapper_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "mmapper",
@@ -109,13 +111,13 @@ static int __init mmapper_init(void)
printk(KERN_INFO "Mapper v0.1\n");
v_buf = (char *) find_iomem("mmapper", &mmapper_size);
- if(mmapper_size == 0){
+ if (mmapper_size == 0) {
printk(KERN_ERR "mmapper_init - find_iomem failed\n");
goto out;
}
err = misc_register(&mmapper_dev);
- if(err){
+ if (err) {
printk(KERN_ERR "mmapper - misc_register failed, err = %d\n",
err);
goto out;
@@ -136,9 +138,3 @@ module_exit(mmapper_exit);
MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
-/*
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index d35d0c1ee7f4..8c01fa81a1ae 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -1,33 +1,28 @@
/*
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 by various other people who didn't put their name here.
* Licensed under the GPL.
*/
-#include "linux/kernel.h"
-#include "linux/netdevice.h"
-#include "linux/rtnetlink.h"
-#include "linux/skbuff.h"
-#include "linux/socket.h"
-#include "linux/spinlock.h"
-#include "linux/module.h"
-#include "linux/init.h"
-#include "linux/etherdevice.h"
-#include "linux/list.h"
-#include "linux/inetdevice.h"
-#include "linux/ctype.h"
-#include "linux/bootmem.h"
-#include "linux/ethtool.h"
-#include "linux/platform_device.h"
-#include "asm/uaccess.h"
-#include "kern_util.h"
-#include "net_kern.h"
-#include "net_user.h"
-#include "mconsole_kern.h"
+#include <linux/bootmem.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/inetdevice.h>
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/netdevice.h>
+#include <linux/platform_device.h>
+#include <linux/rtnetlink.h>
+#include <linux/skbuff.h>
+#include <linux/spinlock.h>
#include "init.h"
-#include "irq_user.h"
#include "irq_kern.h"
+#include "irq_user.h"
+#include "mconsole_kern.h"
+#include "net_kern.h"
+#include "net_user.h"
static inline void set_ether_mac(struct net_device *dev, unsigned char *addr)
{
@@ -39,6 +34,46 @@ static inline void set_ether_mac(struct net_device *dev, unsigned char *addr)
static DEFINE_SPINLOCK(opened_lock);
static LIST_HEAD(opened);
+/*
+ * The drop_skb is used when we can't allocate an skb. The
+ * packet is read into drop_skb in order to get the data off the
+ * connection to the host.
+ * It is reallocated whenever a maximum packet size is seen which is
+ * larger than any seen before. update_drop_skb is called from
+ * eth_configure when a new interface is added.
+ */
+static DEFINE_SPINLOCK(drop_lock);
+static struct sk_buff *drop_skb;
+static int drop_max;
+
+static int update_drop_skb(int max)
+{
+ struct sk_buff *new;
+ unsigned long flags;
+ int err = 0;
+
+ spin_lock_irqsave(&drop_lock, flags);
+
+ if (max <= drop_max)
+ goto out;
+
+ err = -ENOMEM;
+ new = dev_alloc_skb(max);
+ if (new == NULL)
+ goto out;
+
+ skb_put(new, max);
+
+ kfree_skb(drop_skb);
+ drop_skb = new;
+ drop_max = max;
+ err = 0;
+out:
+ spin_unlock_irqrestore(&drop_lock, flags);
+
+ return err;
+}
+
static int uml_net_rx(struct net_device *dev)
{
struct uml_net_private *lp = dev->priv;
@@ -46,16 +81,19 @@ static int uml_net_rx(struct net_device *dev)
struct sk_buff *skb;
/* If we can't allocate memory, try again next round. */
- skb = dev_alloc_skb(dev->mtu);
+ skb = dev_alloc_skb(lp->max_packet);
if (skb == NULL) {
+ drop_skb->dev = dev;
+ /* Read a packet into drop_skb and don't do anything with it. */
+ (*lp->read)(lp->fd, drop_skb, lp);
lp->stats.rx_dropped++;
return 0;
}
skb->dev = dev;
- skb_put(skb, dev->mtu);
+ skb_put(skb, lp->max_packet);
skb_reset_mac_header(skb);
- pkt_len = (*lp->read)(lp->fd, &skb, lp);
+ pkt_len = (*lp->read)(lp->fd, skb, lp);
if (pkt_len > 0) {
skb_trim(skb, pkt_len);
@@ -84,12 +122,12 @@ irqreturn_t uml_net_interrupt(int irq, void *dev_id)
struct uml_net_private *lp = dev->priv;
int err;
- if(!netif_running(dev))
- return(IRQ_NONE);
+ if (!netif_running(dev))
+ return IRQ_NONE;
spin_lock(&lp->lock);
- while((err = uml_net_rx(dev)) > 0) ;
- if(err < 0) {
+ while ((err = uml_net_rx(dev)) > 0) ;
+ if (err < 0) {
printk(KERN_ERR
"Device '%s' read returned %d, shutting it down\n",
dev->name, err);
@@ -115,20 +153,20 @@ static int uml_net_open(struct net_device *dev)
struct uml_net_private *lp = dev->priv;
int err;
- if(lp->fd >= 0){
+ if (lp->fd >= 0) {
err = -ENXIO;
goto out;
}
lp->fd = (*lp->open)(&lp->user);
- if(lp->fd < 0){
+ if (lp->fd < 0) {
err = lp->fd;
goto out;
}
err = um_request_irq(dev->irq, lp->fd, IRQ_READ, uml_net_interrupt,
IRQF_DISABLED | IRQF_SHARED, dev->name, dev);
- if(err != 0){
+ if (err != 0) {
printk(KERN_ERR "uml_net_open: failed to get irq(%d)\n", err);
err = -ENETUNREACH;
goto out_close;
@@ -141,7 +179,7 @@ static int uml_net_open(struct net_device *dev)
* is full when we get here. In this case, new data is never queued,
* SIGIOs never arrive, and the net never works.
*/
- while((err = uml_net_rx(dev)) > 0) ;
+ while ((err = uml_net_rx(dev)) > 0) ;
spin_lock(&opened_lock);
list_add(&lp->list, &opened);
@@ -149,7 +187,7 @@ static int uml_net_open(struct net_device *dev)
return 0;
out_close:
- if(lp->close != NULL) (*lp->close)(lp->fd, &lp->user);
+ if (lp->close != NULL) (*lp->close)(lp->fd, &lp->user);
lp->fd = -1;
out:
return err;
@@ -162,7 +200,7 @@ static int uml_net_close(struct net_device *dev)
netif_stop_queue(dev);
free_irq(dev->irq, dev);
- if(lp->close != NULL)
+ if (lp->close != NULL)
(*lp->close)(lp->fd, &lp->user);
lp->fd = -1;
@@ -183,9 +221,9 @@ static int uml_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
spin_lock_irqsave(&lp->lock, flags);
- len = (*lp->write)(lp->fd, &skb, lp);
+ len = (*lp->write)(lp->fd, skb, lp);
- if(len == skb->len) {
+ if (len == skb->len) {
lp->stats.tx_packets++;
lp->stats.tx_bytes += skb->len;
dev->trans_start = jiffies;
@@ -194,7 +232,7 @@ static int uml_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
/* this is normally done in the interrupt when tx finishes */
netif_wake_queue(dev);
}
- else if(len == 0){
+ else if (len == 0) {
netif_start_queue(dev);
lp->stats.tx_dropped++;
}
@@ -218,8 +256,10 @@ static struct net_device_stats *uml_net_get_stats(struct net_device *dev)
static void uml_net_set_multicast_list(struct net_device *dev)
{
- if (dev->flags & IFF_PROMISC) return;
- else if (dev->mc_count) dev->flags |= IFF_ALLMULTI;
+ if (dev->flags & IFF_PROMISC)
+ return;
+ else if (dev->mc_count)
+ dev->flags |= IFF_ALLMULTI;
else dev->flags &= ~IFF_ALLMULTI;
}
@@ -243,22 +283,9 @@ static int uml_net_set_mac(struct net_device *dev, void *addr)
static int uml_net_change_mtu(struct net_device *dev, int new_mtu)
{
- struct uml_net_private *lp = dev->priv;
- int err = 0;
-
- spin_lock_irq(&lp->lock);
-
- new_mtu = (*lp->set_mtu)(new_mtu, &lp->user);
- if(new_mtu < 0){
- err = new_mtu;
- goto out;
- }
-
dev->mtu = new_mtu;
- out:
- spin_unlock_irq(&lp->lock);
- return err;
+ return 0;
}
static void uml_net_get_drvinfo(struct net_device *dev,
@@ -288,13 +315,13 @@ static void setup_etheraddr(char *str, unsigned char *addr, char *name)
char *end;
int i;
- if(str == NULL)
+ if (str == NULL)
goto random;
- for(i=0;i<6;i++){
+ for (i = 0;i < 6; i++) {
addr[i] = simple_strtoul(str, &end, 16);
- if((end == str) ||
- ((*end != ':') && (*end != ',') && (*end != '\0'))){
+ if ((end == str) ||
+ ((*end != ':') && (*end != ',') && (*end != '\0'))) {
printk(KERN_ERR
"setup_etheraddr: failed to parse '%s' "
"as an ethernet address\n", str);
@@ -349,7 +376,7 @@ static void net_device_release(struct device *dev)
struct net_device *netdev = device->dev;
struct uml_net_private *lp = netdev->priv;
- if(lp->remove != NULL)
+ if (lp->remove != NULL)
(*lp->remove)(&lp->user);
list_del(&device->list);
kfree(device);
@@ -413,7 +440,7 @@ static void eth_configure(int n, void *init, char *mac,
device->pdev.name = DRIVER_NAME;
device->pdev.dev.release = net_device_release;
device->pdev.dev.driver_data = device;
- if(platform_device_register(&device->pdev))
+ if (platform_device_register(&device->pdev))
goto out_free_netdev;
SET_NETDEV_DEV(dev,&device->pdev.dev);
@@ -430,6 +457,7 @@ static void eth_configure(int n, void *init, char *mac,
.dev = dev,
.fd = -1,
.mac = { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0},
+ .max_packet = transport->user->max_packet,
.protocol = transport->kern->protocol,
.open = transport->user->open,
.close = transport->user->close,
@@ -437,8 +465,7 @@ static void eth_configure(int n, void *init, char *mac,
.read = transport->kern->read,
.write = transport->kern->write,
.add_address = transport->user->add_address,
- .delete_address = transport->user->delete_address,
- .set_mtu = transport->user->set_mtu });
+ .delete_address = transport->user->delete_address });
init_timer(&lp->tl);
spin_lock_init(&lp->lock);
@@ -450,7 +477,7 @@ static void eth_configure(int n, void *init, char *mac,
goto out_unregister;
set_ether_mac(dev, device->mac);
- dev->mtu = transport->user->max_packet;
+ dev->mtu = transport->user->mtu;
dev->open = uml_net_open;
dev->hard_start_xmit = uml_net_start_xmit;
dev->stop = uml_net_close;
@@ -463,6 +490,10 @@ static void eth_configure(int n, void *init, char *mac,
dev->watchdog_timeo = (HZ >> 1);
dev->irq = UM_ETH_IRQ;
+ err = update_drop_skb(lp->max_packet);
+ if (err)
+ goto out_undo_user_init;
+
rtnl_lock();
err = register_netdevice(dev);
rtnl_unlock();
@@ -493,9 +524,9 @@ static struct uml_net *find_device(int n)
struct list_head *ele;
spin_lock(&devices_lock);
- list_for_each(ele, &devices){
+ list_for_each(ele, &devices) {
device = list_entry(ele, struct uml_net, list);
- if(device->index == n)
+ if (device->index == n)
goto out;
}
device = NULL;
@@ -511,19 +542,19 @@ static int eth_parse(char *str, int *index_out, char **str_out,
int n, err = -EINVAL;;
n = simple_strtoul(str, &end, 0);
- if(end == str){
+ if (end == str) {
*error_out = "Bad device number";
return err;
}
str = end;
- if(*str != '='){
+ if (*str != '=') {
*error_out = "Expected '=' after device number";
return err;
}
str++;
- if(find_device(n)){
+ if (find_device(n)) {
*error_out = "Device already configured";
return err;
}
@@ -551,20 +582,20 @@ static int check_transport(struct transport *transport, char *eth, int n,
int len;
len = strlen(transport->name);
- if(strncmp(eth, transport->name, len))
+ if (strncmp(eth, transport->name, len))
return 0;
eth += len;
- if(*eth == ',')
+ if (*eth == ',')
eth++;
- else if(*eth != '\0')
+ else if (*eth != '\0')
return 0;
*init_out = kmalloc(transport->setup_size, GFP_KERNEL);
- if(*init_out == NULL)
+ if (*init_out == NULL)
return 1;
- if(!transport->setup(eth, mac_out, *init_out)){
+ if (!transport->setup(eth, mac_out, *init_out)) {
kfree(*init_out);
*init_out = NULL;
}
@@ -584,13 +615,13 @@ void register_transport(struct transport *new)
list_add(&new->list, &transports);
spin_unlock(&transports_lock);
- list_for_each_safe(ele, next, &eth_cmd_line){
+ list_for_each_safe(ele, next, &eth_cmd_line) {
eth = list_entry(ele, struct eth_init, list);
match = check_transport(new, eth->init, eth->index, &init,
&mac);
- if(!match)
+ if (!match)
continue;
- else if(init != NULL){
+ else if (init != NULL) {
eth_configure(eth->index, init, mac, new);
kfree(init);
}
@@ -607,11 +638,11 @@ static int eth_setup_common(char *str, int index)
int found = 0;
spin_lock(&transports_lock);
- list_for_each(ele, &transports){
+ list_for_each(ele, &transports) {
transport = list_entry(ele, struct transport, list);
- if(!check_transport(transport, str, index, &init, &mac))
+ if (!check_transport(transport, str, index, &init, &mac))
continue;
- if(init != NULL){
+ if (init != NULL) {
eth_configure(index, init, mac, transport);
kfree(init);
}
@@ -630,15 +661,15 @@ static int __init eth_setup(char *str)
int n, err;
err = eth_parse(str, &n, &str, &error);
- if(err){
+ if (err) {
printk(KERN_ERR "eth_setup - Couldn't parse '%s' : %s\n",
str, error);
return 1;
}
new = alloc_bootmem(sizeof(*new));
- if (new == NULL){
- printk("eth_init : alloc_bootmem failed\n");
+ if (new == NULL) {
+ printk(KERN_ERR "eth_init : alloc_bootmem failed\n");
return 1;
}
@@ -661,36 +692,36 @@ static int net_config(char *str, char **error_out)
int n, err;
err = eth_parse(str, &n, &str, error_out);
- if(err)
+ if (err)
return err;
/* This string is broken up and the pieces used by the underlying
* driver. So, it is freed only if eth_setup_common fails.
*/
str = kstrdup(str, GFP_KERNEL);
- if(str == NULL){
+ if (str == NULL) {
*error_out = "net_config failed to strdup string";
return -ENOMEM;
}
err = !eth_setup_common(str, n);
- if(err)
+ if (err)
kfree(str);
- return(err);
+ return err;
}
static int net_id(char **str, int *start_out, int *end_out)
{
- char *end;
- int n;
+ char *end;
+ int n;
n = simple_strtoul(*str, &end, 0);
- if((*end != '\0') || (end == *str))
+ if ((*end != '\0') || (end == *str))
return -1;
- *start_out = n;
- *end_out = n;
- *str = end;
- return n;
+ *start_out = n;
+ *end_out = n;
+ *str = end;
+ return n;
}
static int net_remove(int n, char **error_out)
@@ -700,12 +731,12 @@ static int net_remove(int n, char **error_out)
struct uml_net_private *lp;
device = find_device(n);
- if(device == NULL)
+ if (device == NULL)
return -ENODEV;
dev = device->dev;
lp = dev->priv;
- if(lp->fd > 0)
+ if (lp->fd > 0)
return -EBUSY;
unregister_netdev(dev);
platform_device_unregister(&device->pdev);
@@ -731,13 +762,13 @@ static int uml_inetaddr_event(struct notifier_block *this, unsigned long event,
void (*proc)(unsigned char *, unsigned char *, void *);
unsigned char addr_buf[4], netmask_buf[4];
- if(dev->open != uml_net_open)
+ if (dev->open != uml_net_open)
return NOTIFY_DONE;
lp = dev->priv;
proc = NULL;
- switch (event){
+ switch (event) {
case NETDEV_UP:
proc = lp->add_address;
break;
@@ -745,7 +776,7 @@ static int uml_inetaddr_event(struct notifier_block *this, unsigned long event,
proc = lp->delete_address;
break;
}
- if(proc != NULL){
+ if (proc != NULL) {
memcpy(addr_buf, &ifa->ifa_address, sizeof(addr_buf));
memcpy(netmask_buf, &ifa->ifa_mask, sizeof(netmask_buf));
(*proc)(addr_buf, netmask_buf, &lp->user);
@@ -773,13 +804,13 @@ static int uml_net_init(void)
* addresses which have already been set up get handled properly.
*/
spin_lock(&opened_lock);
- list_for_each(ele, &opened){
+ list_for_each(ele, &opened) {
lp = list_entry(ele, struct uml_net_private, list);
ip = lp->dev->ip_ptr;
- if(ip == NULL)
+ if (ip == NULL)
continue;
in = ip->ifa_list;
- while(in != NULL){
+ while (in != NULL) {
uml_inetaddr_event(NULL, NETDEV_UP, in);
in = in->ifa_next;
}
@@ -797,12 +828,12 @@ static void close_devices(void)
struct uml_net_private *lp;
spin_lock(&opened_lock);
- list_for_each(ele, &opened){
+ list_for_each(ele, &opened) {
lp = list_entry(ele, struct uml_net_private, list);
free_irq(lp->dev->irq, lp->dev);
- if((lp->close != NULL) && (lp->fd >= 0))
+ if ((lp->close != NULL) && (lp->fd >= 0))
(*lp->close)(lp->fd, &lp->user);
- if(lp->remove != NULL)
+ if (lp->remove != NULL)
(*lp->remove)(&lp->user);
}
spin_unlock(&opened_lock);
@@ -810,19 +841,6 @@ static void close_devices(void)
__uml_exitcall(close_devices);
-struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra)
-{
- if((skb != NULL) && (skb_tailroom(skb) < extra)){
- struct sk_buff *skb2;
-
- skb2 = skb_copy_expand(skb, 0, extra, GFP_ATOMIC);
- dev_kfree_skb(skb);
- skb = skb2;
- }
- if(skb != NULL) skb_put(skb, extra);
- return(skb);
-}
-
void iter_addresses(void *d, void (*cb)(unsigned char *, unsigned char *,
void *),
void *arg)
@@ -832,9 +850,9 @@ void iter_addresses(void *d, void (*cb)(unsigned char *, unsigned char *,
struct in_ifaddr *in;
unsigned char address[4], netmask[4];
- if(ip == NULL) return;
+ if (ip == NULL) return;
in = ip->ifa_list;
- while(in != NULL){
+ while (in != NULL) {
memcpy(address, &in->ifa_address, sizeof(address));
memcpy(netmask, &in->ifa_mask, sizeof(netmask));
(*cb)(address, netmask, arg);
@@ -849,15 +867,15 @@ int dev_netmask(void *d, void *m)
struct in_ifaddr *in;
__be32 *mask_out = m;
- if(ip == NULL)
- return(1);
+ if (ip == NULL)
+ return 1;
in = ip->ifa_list;
- if(in == NULL)
- return(1);
+ if (in == NULL)
+ return 1;
*mask_out = in->ifa_mask;
- return(0);
+ return 0;
}
void *get_output_buffer(int *len_out)
@@ -865,7 +883,7 @@ void *get_output_buffer(int *len_out)
void *ret;
ret = (void *) __get_free_pages(GFP_KERNEL, 0);
- if(ret) *len_out = PAGE_SIZE;
+ if (ret) *len_out = PAGE_SIZE;
else *len_out = 0;
return ret;
}
@@ -881,16 +899,16 @@ int tap_setup_common(char *str, char *type, char **dev_name, char **mac_out,
char *remain;
remain = split_if_spec(str, dev_name, mac_out, gate_addr, NULL);
- if(remain != NULL){
- printk("tap_setup_common - Extra garbage on specification : "
- "'%s'\n", remain);
- return(1);
+ if (remain != NULL) {
+ printk(KERN_ERR "tap_setup_common - Extra garbage on "
+ "specification : '%s'\n", remain);
+ return 1;
}
- return(0);
+ return 0;
}
unsigned short eth_protocol(struct sk_buff *skb)
{
- return(eth_type_trans(skb, skb->dev));
+ return eth_type_trans(skb, skb->dev);
}
diff --git a/arch/um/drivers/net_user.c b/arch/um/drivers/net_user.c
index da946e3e1bf2..90d7f2e8ead8 100644
--- a/arch/um/drivers/net_user.c
+++ b/arch/um/drivers/net_user.c
@@ -1,34 +1,32 @@
-/*
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
+/*
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
-#include <stddef.h>
-#include <stdarg.h>
-#include <unistd.h>
#include <stdio.h>
+#include <unistd.h>
+#include <stdarg.h>
#include <errno.h>
-#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/wait.h>
-#include <sys/time.h>
-#include "user.h"
-#include "kern_util.h"
#include "net_user.h"
+#include "kern_constants.h"
#include "os.h"
#include "um_malloc.h"
-#include "kern_constants.h"
+#include "user.h"
int tap_open_common(void *dev, char *gate_addr)
{
int tap_addr[4];
- if(gate_addr == NULL)
+ if (gate_addr == NULL)
return 0;
- if(sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
- &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4){
- printk("Invalid tap IP address - '%s'\n", gate_addr);
+ if (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
+ &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4) {
+ printk(UM_KERN_ERR "Invalid tap IP address - '%s'\n",
+ gate_addr);
return -EINVAL;
}
return 0;
@@ -38,15 +36,15 @@ void tap_check_ips(char *gate_addr, unsigned char *eth_addr)
{
int tap_addr[4];
- if((gate_addr != NULL) &&
- (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
- &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) &&
- (eth_addr[0] == tap_addr[0]) &&
- (eth_addr[1] == tap_addr[1]) &&
- (eth_addr[2] == tap_addr[2]) &&
- (eth_addr[3] == tap_addr[3])){
- printk("The tap IP address and the UML eth IP address"
- " must be different\n");
+ if ((gate_addr != NULL) &&
+ (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
+ &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) &&
+ (eth_addr[0] == tap_addr[0]) &&
+ (eth_addr[1] == tap_addr[1]) &&
+ (eth_addr[2] == tap_addr[2]) &&
+ (eth_addr[3] == tap_addr[3])) {
+ printk(UM_KERN_ERR "The tap IP address and the UML eth IP "
+ "address must be different\n");
}
}
@@ -57,24 +55,28 @@ void read_output(int fd, char *output, int len)
char c;
char *str;
- if(output == NULL){
+ if (output == NULL) {
output = &c;
len = sizeof(c);
}
-
+
*output = '\0';
- ret = os_read_file(fd, &remain, sizeof(remain));
+ ret = read(fd, &remain, sizeof(remain));
if (ret != sizeof(remain)) {
+ if (ret < 0)
+ ret = -errno;
expected = sizeof(remain);
str = "length";
goto err;
}
- while(remain != 0){
+ while (remain != 0) {
expected = (remain < len) ? remain : len;
- ret = os_read_file(fd, output, expected);
+ ret = read(fd, output, expected);
if (ret != expected) {
+ if (ret < 0)
+ ret = -errno;
str = "data";
goto err;
}
@@ -85,20 +87,22 @@ void read_output(int fd, char *output, int len)
err:
if (ret < 0)
- printk("read_output - read of %s failed, errno = %d\n", str, -ret);
+ printk(UM_KERN_ERR "read_output - read of %s failed, "
+ "errno = %d\n", str, -ret);
else
- printk("read_output - read of %s failed, read only %d of %d bytes\n", str, ret, expected);
+ printk(UM_KERN_ERR "read_output - read of %s failed, read only "
+ "%d of %d bytes\n", str, ret, expected);
}
int net_read(int fd, void *buf, int len)
{
int n;
- n = os_read_file(fd, buf, len);
+ n = read(fd, buf, len);
- if(n == -EAGAIN)
+ if ((n < 0) && (errno == EAGAIN))
return 0;
- else if(n == 0)
+ else if (n == 0)
return -ENOTCONN;
return n;
}
@@ -108,12 +112,12 @@ int net_recvfrom(int fd, void *buf, int len)
int n;
CATCH_EINTR(n = recvfrom(fd, buf, len, 0, NULL, NULL));
- if(n < 0){
- if(errno == EAGAIN)
+ if (n < 0) {
+ if (errno == EAGAIN)
return 0;
return -errno;
}
- else if(n == 0)
+ else if (n == 0)
return -ENOTCONN;
return n;
}
@@ -122,11 +126,11 @@ int net_write(int fd, void *buf, int len)
{
int n;
- n = os_write_file(fd, buf, len);
+ n = write(fd, buf, len);
- if(n == -EAGAIN)
+ if ((n < 0) && (errno == EAGAIN))
return 0;
- else if(n == 0)
+ else if (n == 0)
return -ENOTCONN;
return n;
}
@@ -136,12 +140,12 @@ int net_send(int fd, void *buf, int len)
int n;
CATCH_EINTR(n = send(fd, buf, len, 0));
- if(n < 0){
- if(errno == EAGAIN)
+ if (n < 0) {
+ if (errno == EAGAIN)
return 0;
return -errno;
}
- else if(n == 0)
+ else if (n == 0)
return -ENOTCONN;
return n;
}
@@ -152,12 +156,12 @@ int net_sendto(int fd, void *buf, int len, void *to, int sock_len)
CATCH_EINTR(n = sendto(fd, buf, len, 0, (struct sockaddr *) to,
sock_len));
- if(n < 0){
- if(errno == EAGAIN)
+ if (n < 0) {
+ if (errno == EAGAIN)
return 0;
return -errno;
}
- else if(n == 0)
+ else if (n == 0)
return -ENOTCONN;
return n;
}
@@ -171,7 +175,7 @@ static void change_pre_exec(void *arg)
{
struct change_pre_exec_data *data = arg;
- os_close_file(data->close_me);
+ close(data->close_me);
dup2(data->stdout, 1);
}
@@ -181,8 +185,9 @@ static int change_tramp(char **argv, char *output, int output_len)
struct change_pre_exec_data pe_data;
err = os_pipe(fds, 1, 0);
- if(err < 0){
- printk("change_tramp - pipe failed, err = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "change_tramp - pipe failed, err = %d\n",
+ -err);
return err;
}
pe_data.close_me = fds[0];
@@ -192,8 +197,8 @@ static int change_tramp(char **argv, char *output, int output_len)
if (pid > 0) /* Avoid hang as we won't get data in failure case. */
read_output(fds[0], output, output_len);
- os_close_file(fds[0]);
- os_close_file(fds[1]);
+ close(fds[0]);
+ close(fds[1]);
if (pid > 0)
CATCH_EINTR(err = waitpid(pid, NULL, 0));
@@ -206,25 +211,26 @@ static void change(char *dev, char *what, unsigned char *addr,
char addr_buf[sizeof("255.255.255.255\0")];
char netmask_buf[sizeof("255.255.255.255\0")];
char version[sizeof("nnnnn\0")];
- char *argv[] = { "uml_net", version, what, dev, addr_buf,
+ char *argv[] = { "uml_net", version, what, dev, addr_buf,
netmask_buf, NULL };
char *output;
int output_len, pid;
sprintf(version, "%d", UML_NET_VERSION);
sprintf(addr_buf, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
- sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1],
+ sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1],
netmask[2], netmask[3]);
output_len = UM_KERN_PAGE_SIZE;
output = kmalloc(output_len, UM_GFP_KERNEL);
- if(output == NULL)
- printk("change : failed to allocate output buffer\n");
+ if (output == NULL)
+ printk(UM_KERN_ERR "change : failed to allocate output "
+ "buffer\n");
pid = change_tramp(argv, output, output_len);
- if(pid < 0) return;
+ if (pid < 0) return;
- if(output != NULL){
+ if (output != NULL) {
printk("%s", output);
kfree(output);
}
@@ -246,13 +252,13 @@ char *split_if_spec(char *str, ...)
va_list ap;
va_start(ap, str);
- while((arg = va_arg(ap, char **)) != NULL){
- if(*str == '\0')
+ while ((arg = va_arg(ap, char **)) != NULL) {
+ if (*str == '\0')
return NULL;
end = strchr(str, ',');
- if(end != str)
+ if (end != str)
*arg = str;
- if(end == NULL)
+ if (end == NULL)
return NULL;
*end++ = '\0';
str = end;
diff --git a/arch/um/drivers/null.c b/arch/um/drivers/null.c
index 9016c68beee8..21ad3d7932b3 100644
--- a/arch/um/drivers/null.c
+++ b/arch/um/drivers/null.c
@@ -1,10 +1,11 @@
-/*
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+/*
+ * 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 <fcntl.h>
#include "chan_user.h"
#include "os.h"
@@ -13,19 +14,23 @@ 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:
- */
diff --git a/arch/um/drivers/pcap_kern.c b/arch/um/drivers/pcap_kern.c
index c329931673d6..3a750dd39be1 100644
--- a/arch/um/drivers/pcap_kern.c
+++ b/arch/um/drivers/pcap_kern.c
@@ -1,13 +1,11 @@
/*
- * Copyright (C) 2002 Jeff Dike <jdike@karaya.com>
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL.
*/
#include "linux/init.h"
-#include "linux/netdevice.h"
-#include "linux/etherdevice.h"
+#include <linux/netdevice.h>
#include "net_kern.h"
-#include "net_user.h"
#include "pcap_user.h"
struct pcap_init {
@@ -33,19 +31,14 @@ void pcap_init(struct net_device *dev, void *data)
printk("pcap backend, host interface %s\n", ppri->host_if);
}
-static int pcap_read(int fd, struct sk_buff **skb,
- struct uml_net_private *lp)
+static int pcap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
- if(*skb == NULL)
- return -ENOMEM;
-
- return pcap_user_read(fd, skb_mac_header(*skb),
- (*skb)->dev->mtu + ETH_HEADER_OTHER,
+ return pcap_user_read(fd, skb_mac_header(skb),
+ skb->dev->mtu + ETH_HEADER_OTHER,
(struct pcap_data *) &lp->user);
}
-static int pcap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
+static int pcap_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
return -EPERM;
}
@@ -71,28 +64,29 @@ int pcap_setup(char *str, char **mac_out, void *data)
remain = split_if_spec(str, &host_if, &init->filter,
&options[0], &options[1], mac_out, NULL);
- if(remain != NULL){
+ if (remain != NULL) {
printk(KERN_ERR "pcap_setup - Extra garbage on "
"specification : '%s'\n", remain);
return 0;
}
- if(host_if != NULL)
+ if (host_if != NULL)
init->host_if = host_if;
- for(i = 0; i < ARRAY_SIZE(options); i++){
- if(options[i] == NULL)
+ for (i = 0; i < ARRAY_SIZE(options); i++) {
+ if (options[i] == NULL)
continue;
- if(!strcmp(options[i], "promisc"))
+ if (!strcmp(options[i], "promisc"))
init->promisc = 1;
- else if(!strcmp(options[i], "nopromisc"))
+ else if (!strcmp(options[i], "nopromisc"))
init->promisc = 0;
- else if(!strcmp(options[i], "optimize"))
+ else if (!strcmp(options[i], "optimize"))
init->optimize = 1;
- else if(!strcmp(options[i], "nooptimize"))
+ else if (!strcmp(options[i], "nooptimize"))
init->optimize = 0;
else {
- printk("pcap_setup : bad option - '%s'\n", options[i]);
+ printk(KERN_ERR "pcap_setup : bad option - '%s'\n",
+ options[i]);
return 0;
}
}
diff --git a/arch/um/drivers/pcap_user.c b/arch/um/drivers/pcap_user.c
index 1316456e2a28..e9809356c530 100644
--- a/arch/um/drivers/pcap_user.c
+++ b/arch/um/drivers/pcap_user.c
@@ -1,21 +1,17 @@
/*
- * Copyright (C) 2002 Jeff Dike <jdike@karaya.com>
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL.
*/
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
#include <errno.h>
#include <pcap.h>
+#include <string.h>
#include <asm/types.h>
#include "net_user.h"
#include "pcap_user.h"
-#include "user.h"
-#include "um_malloc.h"
#include "kern_constants.h"
-
-#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
+#include "um_malloc.h"
+#include "user.h"
#define PCAP_FD(p) (*(int *)(p))
@@ -25,8 +21,9 @@ static int pcap_user_init(void *data, void *dev)
pcap_t *p;
char errors[PCAP_ERRBUF_SIZE];
- p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors);
- if(p == NULL){
+ p = pcap_open_live(pri->host_if, ETH_MAX_PACKET + ETH_HEADER_OTHER,
+ pri->promisc, 0, errors);
+ if (p == NULL) {
printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - "
"'%s'\n", errors);
return -EINVAL;
@@ -43,50 +40,55 @@ static int pcap_open(void *data)
__u32 netmask;
int err;
- if(pri->pcap == NULL)
+ if (pri->pcap == NULL)
return -ENODEV;
- if(pri->filter != NULL){
+ if (pri->filter != NULL) {
err = dev_netmask(pri->dev, &netmask);
- if(err < 0){
+ if (err < 0) {
printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n");
return -EIO;
}
- pri->compiled = kmalloc(sizeof(struct bpf_program), UM_GFP_KERNEL);
- if(pri->compiled == NULL){
+ pri->compiled = kmalloc(sizeof(struct bpf_program),
+ UM_GFP_KERNEL);
+ if (pri->compiled == NULL) {
printk(UM_KERN_ERR "pcap_open : kmalloc failed\n");
return -ENOMEM;
}
- err = pcap_compile(pri->pcap,
- (struct bpf_program *) pri->compiled,
+ err = pcap_compile(pri->pcap,
+ (struct bpf_program *) pri->compiled,
pri->filter, pri->optimize, netmask);
- if(err < 0){
+ if (err < 0) {
printk(UM_KERN_ERR "pcap_open : pcap_compile failed - "
"'%s'\n", pcap_geterr(pri->pcap));
- return -EIO;
+ goto out;
}
err = pcap_setfilter(pri->pcap, pri->compiled);
- if(err < 0){
+ if (err < 0) {
printk(UM_KERN_ERR "pcap_open : pcap_setfilter "
"failed - '%s'\n", pcap_geterr(pri->pcap));
- return -EIO;
+ goto out;
}
}
return PCAP_FD(pri->pcap);
+
+ out:
+ kfree(pri->compiled);
+ return -EIO;
}
static void pcap_remove(void *data)
{
struct pcap_data *pri = data;
- if(pri->compiled != NULL)
+ if (pri->compiled != NULL)
pcap_freecode(pri->compiled);
- if(pri->pcap != NULL)
+ if (pri->pcap != NULL)
pcap_close(pri->pcap);
}
@@ -95,7 +97,7 @@ struct pcap_handler_data {
int len;
};
-static void handler(u_char *data, const struct pcap_pkthdr *header,
+static void handler(u_char *data, const struct pcap_pkthdr *header,
const u_char *packet)
{
int len;
@@ -115,12 +117,12 @@ int pcap_user_read(int fd, void *buffer, int len, struct pcap_data *pri)
int n;
n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata);
- if(n < 0){
+ if (n < 0) {
printk(UM_KERN_ERR "pcap_dispatch failed - %s\n",
pcap_geterr(pri->pcap));
return -EIO;
}
- else if(n == 0)
+ else if (n == 0)
return 0;
return hdata.len;
}
@@ -130,8 +132,8 @@ const struct net_user_info pcap_user_info = {
.open = pcap_open,
.close = NULL,
.remove = pcap_remove,
- .set_mtu = NULL,
.add_address = NULL,
.delete_address = NULL,
- .max_packet = MAX_PACKET - ETH_HEADER_OTHER
+ .mtu = ETH_MAX_PACKET,
+ .max_packet = ETH_MAX_PACKET + ETH_HEADER_OTHER,
};
diff --git a/arch/um/drivers/port_kern.c b/arch/um/drivers/port_kern.c
index 1c8efd95c421..330543b3129b 100644
--- a/arch/um/drivers/port_kern.c
+++ b/arch/um/drivers/port_kern.c
@@ -1,24 +1,16 @@
/*
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL
*/
-#include "linux/list.h"
-#include "linux/sched.h"
-#include "linux/slab.h"
+#include "linux/completion.h"
#include "linux/interrupt.h"
-#include "linux/spinlock.h"
-#include "linux/errno.h"
+#include "linux/list.h"
#include "asm/atomic.h"
-#include "asm/semaphore.h"
-#include "asm/errno.h"
-#include "kern_util.h"
-#include "kern.h"
-#include "irq_user.h"
-#include "irq_kern.h"
-#include "port.h"
#include "init.h"
+#include "irq_kern.h"
#include "os.h"
+#include "port.h"
struct port_list {
struct list_head list;
@@ -53,8 +45,8 @@ static irqreturn_t pipe_interrupt(int irq, void *data)
int fd;
fd = os_rcv_fd(conn->socket[0], &conn->helper_pid);
- if(fd < 0){
- if(fd == -EAGAIN)
+ if (fd < 0) {
+ if (fd == -EAGAIN)
return IRQ_NONE;
printk(KERN_ERR "pipe_interrupt : os_rcv_fd returned %d\n",
@@ -81,18 +73,18 @@ static irqreturn_t pipe_interrupt(int irq, void *data)
static int port_accept(struct port_list *port)
{
struct connection *conn;
- int fd, socket[2], pid, ret = 0;
+ int fd, socket[2], pid;
fd = port_connection(port->fd, socket, &pid);
- if(fd < 0){
- if(fd != -EAGAIN)
+ if (fd < 0) {
+ if (fd != -EAGAIN)
printk(KERN_ERR "port_accept : port_connection "
"returned %d\n", -fd);
goto out;
}
conn = kmalloc(sizeof(*conn), GFP_ATOMIC);
- if(conn == NULL){
+ if (conn == NULL) {
printk(KERN_ERR "port_accept : failed to allocate "
"connection\n");
goto out_close;
@@ -104,17 +96,17 @@ static int port_accept(struct port_list *port)
.telnetd_pid = pid,
.port = port });
- if(um_request_irq(TELNETD_IRQ, socket[0], IRQ_READ, pipe_interrupt,
+ if (um_request_irq(TELNETD_IRQ, socket[0], IRQ_READ, pipe_interrupt,
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
- "telnetd", conn)){
+ "telnetd", conn)) {
printk(KERN_ERR "port_accept : failed to get IRQ for "
"telnetd\n");
goto out_free;
}
- if(atomic_read(&port->wait_count) == 0){
+ if (atomic_read(&port->wait_count) == 0) {
os_write_file(fd, NO_WAITER_MSG, sizeof(NO_WAITER_MSG));
- printk("No one waiting for port\n");
+ printk(KERN_ERR "No one waiting for port\n");
}
list_add(&conn->list, &port->pending);
return 1;
@@ -123,28 +115,29 @@ static int port_accept(struct port_list *port)
kfree(conn);
out_close:
os_close_file(fd);
- if(pid != -1)
- os_kill_process(pid, 1);
+ os_kill_process(pid, 1);
out:
- return ret;
+ return 0;
}
static DECLARE_MUTEX(ports_sem);
static LIST_HEAD(ports);
-void port_work_proc(struct work_struct *unused)
+static void port_work_proc(struct work_struct *unused)
{
struct port_list *port;
struct list_head *ele;
unsigned long flags;
local_irq_save(flags);
- list_for_each(ele, &ports){
+ list_for_each(ele, &ports) {
port = list_entry(ele, struct port_list, list);
- if(!port->has_connection)
+ if (!port->has_connection)
continue;
+
reactivate_fd(port->fd, ACCEPT_IRQ);
- while(port_accept(port)) ;
+ while (port_accept(port))
+ ;
port->has_connection = 0;
}
local_irq_restore(flags);
@@ -169,25 +162,27 @@ void *port_data(int port_num)
int fd;
down(&ports_sem);
- list_for_each(ele, &ports){
+ list_for_each(ele, &ports) {
port = list_entry(ele, struct port_list, list);
- if(port->port == port_num) goto found;
+ if (port->port == port_num)
+ goto found;
}
port = kmalloc(sizeof(struct port_list), GFP_KERNEL);
- if(port == NULL){
+ if (port == NULL) {
printk(KERN_ERR "Allocation of port list failed\n");
goto out;
}
fd = port_listen_fd(port_num);
- if(fd < 0){
+ if (fd < 0) {
printk(KERN_ERR "binding to port %d failed, errno = %d\n",
port_num, -fd);
goto out_free;
}
- if(um_request_irq(ACCEPT_IRQ, fd, IRQ_READ, port_interrupt,
+
+ if (um_request_irq(ACCEPT_IRQ, fd, IRQ_READ, port_interrupt,
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
- "port", port)){
+ "port", port)) {
printk(KERN_ERR "Failed to get IRQ for port %d\n", port_num);
goto out_close;
}
@@ -206,7 +201,7 @@ void *port_data(int port_num)
found:
dev = kmalloc(sizeof(struct port_dev), GFP_KERNEL);
- if(dev == NULL){
+ if (dev == NULL) {
printk(KERN_ERR "Allocation of port device entry failed\n");
goto out;
}
@@ -216,10 +211,10 @@ void *port_data(int port_num)
.telnetd_pid = -1 });
goto out;
- out_free:
- kfree(port);
out_close:
os_close_file(fd);
+ out_free:
+ kfree(port);
out:
up(&ports_sem);
return dev;
@@ -233,9 +228,9 @@ int port_wait(void *data)
int fd;
atomic_inc(&port->wait_count);
- while(1){
+ while (1) {
fd = -ERESTARTSYS;
- if(wait_for_completion_interruptible(&port->done))
+ if (wait_for_completion_interruptible(&port->done))
goto out;
spin_lock(&port->lock);
@@ -258,7 +253,8 @@ int port_wait(void *data)
*/
free_irq(TELNETD_IRQ, conn);
- if(conn->fd >= 0) break;
+ if (conn->fd >= 0)
+ break;
os_close_file(conn->fd);
kfree(conn);
}
@@ -276,9 +272,9 @@ void port_remove_dev(void *d)
{
struct port_dev *dev = d;
- if(dev->helper_pid != -1)
+ if (dev->helper_pid != -1)
os_kill_process(dev->helper_pid, 0);
- if(dev->telnetd_pid != -1)
+ if (dev->telnetd_pid != -1)
os_kill_process(dev->telnetd_pid, 1);
dev->helper_pid = -1;
dev->telnetd_pid = -1;
@@ -297,7 +293,7 @@ static void free_port(void)
struct list_head *ele;
struct port_list *port;
- list_for_each(ele, &ports){
+ list_for_each(ele, &ports) {
port = list_entry(ele, struct port_list, list);
free_irq_by_fd(port->fd);
os_close_file(port->fd);
diff --git a/arch/um/drivers/port_user.c b/arch/um/drivers/port_user.c
index c799b00012c7..addd75902656 100644
--- a/arch/um/drivers/port_user.c
+++ b/arch/um/drivers/port_user.c
@@ -1,24 +1,20 @@
/*
- * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL
*/
#include <stdio.h>
-#include <stddef.h>
#include <stdlib.h>
-#include <string.h>
#include <errno.h>
-#include <unistd.h>
#include <termios.h>
-#include <sys/socket.h>
-#include <sys/un.h>
+#include <unistd.h>
#include <netinet/in.h>
-#include "kern_util.h"
-#include "user.h"
#include "chan_user.h"
-#include "port.h"
+#include "kern_constants.h"
#include "os.h"
+#include "port.h"
#include "um_malloc.h"
+#include "user.h"
struct port_chan {
int raw;
@@ -34,24 +30,25 @@ static void *port_init(char *str, int device, const struct chan_opts *opts)
char *end;
int port;
- if(*str != ':'){
- printk("port_init : channel type 'port' must specify a "
- "port number\n");
+ if (*str != ':') {
+ printk(UM_KERN_ERR "port_init : channel type 'port' must "
+ "specify a port number\n");
return NULL;
}
str++;
port = strtoul(str, &end, 0);
- if((*end != '\0') || (end == str)){
- printk("port_init : couldn't parse port '%s'\n", str);
+ if ((*end != '\0') || (end == str)) {
+ printk(UM_KERN_ERR "port_init : couldn't parse port '%s'\n",
+ str);
return NULL;
}
kern_data = port_data(port);
- if(kern_data == NULL)
+ if (kern_data == NULL)
return NULL;
data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
- if(data == NULL)
+ if (data == NULL)
goto err;
*data = ((struct port_chan) { .raw = opts->raw,
@@ -79,13 +76,13 @@ static int port_open(int input, int output, int primary, void *d,
int fd, err;
fd = port_wait(data->kernel_data);
- if((fd >= 0) && data->raw){
+ if ((fd >= 0) && data->raw) {
CATCH_EINTR(err = tcgetattr(fd, &data->tt));
- if(err)
+ if (err)
return err;
err = raw(fd);
- if(err)
+ if (err)
return err;
}
*dev_out = data->dev;
@@ -119,11 +116,11 @@ int port_listen_fd(int port)
int fd, err, arg;
fd = socket(PF_INET, SOCK_STREAM, 0);
- if(fd == -1)
+ if (fd == -1)
return -errno;
arg = 1;
- if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof(arg)) < 0){
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof(arg)) < 0) {
err = -errno;
goto out;
}
@@ -131,23 +128,23 @@ int port_listen_fd(int port)
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_ANY);
- if(bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0){
+ if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
err = -errno;
goto out;
}
- if(listen(fd, 1) < 0){
+ if (listen(fd, 1) < 0) {
err = -errno;
goto out;
}
err = os_set_fd_block(fd, 0);
- if(err < 0)
+ if (err < 0)
goto out;
return fd;
out:
- os_close_file(fd);
+ close(fd);
return err;
}
@@ -163,10 +160,10 @@ void port_pre_exec(void *arg)
dup2(data->sock_fd, 0);
dup2(data->sock_fd, 1);
dup2(data->sock_fd, 2);
- os_close_file(data->sock_fd);
+ close(data->sock_fd);
dup2(data->pipe_fd, 3);
- os_shutdown_socket(3, 1, 0);
- os_close_file(data->pipe_fd);
+ shutdown(3, SHUT_RD);
+ close(data->pipe_fd);
}
int port_connection(int fd, int *socket, int *pid_out)
@@ -176,12 +173,12 @@ int port_connection(int fd, int *socket, int *pid_out)
"/usr/lib/uml/port-helper", NULL };
struct port_pre_exec_data data;
- new = os_accept_connection(fd);
- if(new < 0)
- return new;
+ new = accept(fd, NULL, 0);
+ if (new < 0)
+ return -errno;
err = os_pipe(socket, 0, 0);
- if(err < 0)
+ if (err < 0)
goto out_close;
data = ((struct port_pre_exec_data)
@@ -189,18 +186,18 @@ int port_connection(int fd, int *socket, int *pid_out)
.pipe_fd = socket[1] });
err = run_helper(port_pre_exec, &data, argv);
- if(err < 0)
+ if (err < 0)
goto out_shutdown;
*pid_out = err;
return new;
out_shutdown:
- os_shutdown_socket(socket[0], 1, 1);
- os_close_file(socket[0]);
- os_shutdown_socket(socket[1], 1, 1);
- os_close_file(socket[1]);
+ shutdown(socket[0], SHUT_RDWR);
+ close(socket[0]);
+ shutdown(socket[1], SHUT_RDWR);
+ close(socket[1]);
out_close:
- os_close_file(new);
+ close(new);
return err;
}
diff --git a/arch/um/drivers/pty.c b/arch/um/drivers/pty.c
index 1e3fd619a837..49c79dda6046 100644
--- a/arch/um/drivers/pty.c
+++ b/arch/um/drivers/pty.c
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
@@ -6,16 +6,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
#include <termios.h>
#include <sys/stat.h>
#include "chan_user.h"
-#include "os.h"
-#include "user.h"
#include "kern_constants.h"
+#include "os.h"
#include "um_malloc.h"
+#include "user.h"
struct pty_chan {
void (*announce)(char *dev_name, int dev);
@@ -33,7 +33,7 @@ static void *pty_chan_init(char *str, int device, const struct chan_opts *opts)
if (data == NULL)
return NULL;
- *data = ((struct pty_chan) { .announce = opts->announce,
+ *data = ((struct pty_chan) { .announce = opts->announce,
.dev = device,
.raw = opts->raw });
return data;
@@ -56,11 +56,11 @@ static int pts_open(int input, int output, int primary, void *d,
if (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 output, int primary, void *d,
(*data->announce)(dev, data->dev);
return fd;
+
+out_close:
+ close(fd);
+ return err;
}
static int getmaster(char *line)
@@ -97,7 +101,7 @@ static int getmaster(char *line)
*tp = 't';
err = access(line, R_OK | W_OK);
*tp = 'p';
- if(!err)
+ if (!err)
return master;
close(master);
}
@@ -119,12 +123,14 @@ static int pty_open(int input, int output, int primary, void *d,
if (fd < 0)
return fd;
- if(data->raw){
+ if (data->raw) {
err = raw(fd);
- if (err)
+ if (err) {
+ close(fd);
return err;
+ }
}
-
+
if (data->announce)
(*data->announce)(dev, data->dev);
diff --git a/arch/um/drivers/slip_kern.c b/arch/um/drivers/slip_kern.c
index 125c44f77638..ae67e7158e71 100644
--- a/arch/um/drivers/slip_kern.c
+++ b/arch/um/drivers/slip_kern.c
@@ -1,11 +1,12 @@
-#include "linux/kernel.h"
-#include "linux/stddef.h"
-#include "linux/init.h"
-#include "linux/netdevice.h"
-#include "linux/if_arp.h"
+/*
+ * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Licensed under the GPL.
+ */
+
+#include <linux/if_arp.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
#include "net_kern.h"
-#include "net_user.h"
-#include "kern.h"
#include "slip.h"
struct slip_init {
@@ -43,21 +44,19 @@ void slip_init(struct net_device *dev, void *data)
static unsigned short slip_protocol(struct sk_buff *skbuff)
{
- return(htons(ETH_P_IP));
+ return htons(ETH_P_IP);
}
-static int slip_read(int fd, struct sk_buff **skb,
- struct uml_net_private *lp)
+static int slip_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- return(slip_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
- (struct slip_data *) &lp->user));
+ return slip_user_read(fd, skb_mac_header(skb), skb->dev->mtu,
+ (struct slip_data *) &lp->user);
}
-static int slip_write(int fd, struct sk_buff **skb,
- struct uml_net_private *lp)
+static int slip_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- return(slip_user_write(fd, (*skb)->data, (*skb)->len,
- (struct slip_data *) &lp->user));
+ return slip_user_write(fd, skb->data, skb->len,
+ (struct slip_data *) &lp->user);
}
const struct net_kern_info slip_kern_info = {
@@ -71,12 +70,11 @@ static int slip_setup(char *str, char **mac_out, void *data)
{
struct slip_init *init = data;
- *init = ((struct slip_init)
- { .gate_addr = NULL });
+ *init = ((struct slip_init) { .gate_addr = NULL });
- if(str[0] != '\0')
+ if (str[0] != '\0')
init->gate_addr = str;
- return(1);
+ return 1;
}
static struct transport slip_transport = {
diff --git a/arch/um/drivers/slip_user.c b/arch/um/drivers/slip_user.c
index c0b73c28cff0..5f06204d6871 100644
--- a/arch/um/drivers/slip_user.c
+++ b/arch/um/drivers/slip_user.c
@@ -1,21 +1,22 @@
+/*
+ * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Licensed under the GPL.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <stddef.h>
-#include <sched.h>
-#include <string.h>
#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
#include <sys/termios.h>
#include <sys/wait.h>
-#include <sys/signal.h>
-#include "kern_util.h"
-#include "user.h"
+#include "kern_constants.h"
#include "net_user.h"
-#include "slip.h"
-#include "slip_common.h"
#include "os.h"
+#include "slip.h"
#include "um_malloc.h"
-#include "kern_constants.h"
+#include "user.h"
static int slip_user_init(void *data, void *dev)
{
@@ -31,8 +32,9 @@ static int set_up_tty(int fd)
struct termios tios;
if (tcgetattr(fd, &tios) < 0) {
- printk("could not get initial terminal attributes\n");
- return(-1);
+ printk(UM_KERN_ERR "could not get initial terminal "
+ "attributes\n");
+ return -1;
}
tios.c_cflag = CS8 | CREAD | HUPCL | CLOCAL;
@@ -48,10 +50,10 @@ static int set_up_tty(int fd)
cfsetispeed(&tios, B38400);
if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- printk("failed to set terminal attributes\n");
- return(-1);
+ printk(UM_KERN_ERR "failed to set terminal attributes\n");
+ return -1;
}
- return(0);
+ return 0;
}
struct slip_pre_exec_data {
@@ -64,9 +66,11 @@ static void slip_pre_exec(void *arg)
{
struct slip_pre_exec_data *data = arg;
- if(data->stdin >= 0) dup2(data->stdin, 0);
+ if (data->stdin >= 0)
+ dup2(data->stdin, 0);
dup2(data->stdout, 1);
- if(data->close_me >= 0) os_close_file(data->close_me);
+ if (data->close_me >= 0)
+ close(data->close_me);
}
static int slip_tramp(char **argv, int fd)
@@ -76,8 +80,9 @@ static int slip_tramp(char **argv, int fd)
int status, pid, fds[2], err, output_len;
err = os_pipe(fds, 1, 0);
- if(err < 0){
- printk("slip_tramp : pipe failed, err = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "slip_tramp : pipe failed, err = %d\n",
+ -err);
goto out;
}
@@ -86,41 +91,42 @@ static int slip_tramp(char **argv, int fd)
pe_data.stdout = fds[1];
pe_data.close_me = fds[0];
err = run_helper(slip_pre_exec, &pe_data, argv);
- if(err < 0)
+ if (err < 0)
goto out_close;
pid = err;
output_len = UM_KERN_PAGE_SIZE;
output = kmalloc(output_len, UM_GFP_KERNEL);
- if(output == NULL){
- printk("slip_tramp : failed to allocate output buffer\n");
+ if (output == NULL) {
+ printk(UM_KERN_ERR "slip_tramp : failed to allocate output "
+ "buffer\n");
os_kill_process(pid, 1);
err = -ENOMEM;
goto out_free;
}
- os_close_file(fds[1]);
+ close(fds[1]);
read_output(fds[0], output, output_len);
printk("%s", output);
CATCH_EINTR(err = waitpid(pid, &status, 0));
- if(err < 0)
+ if (err < 0)
err = errno;
- else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){
- printk("'%s' didn't exit with status 0\n", argv[0]);
+ else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
+ printk(UM_KERN_ERR "'%s' didn't exit with status 0\n", argv[0]);
err = -EINVAL;
}
else err = 0;
- os_close_file(fds[0]);
+ close(fds[0]);
out_free:
kfree(output);
return err;
out_close:
- os_close_file(fds[0]);
- os_close_file(fds[1]);
+ close(fds[0]);
+ close(fds[1]);
out:
return err;
}
@@ -130,60 +136,64 @@ static int slip_open(void *data)
struct slip_data *pri = data;
char version_buf[sizeof("nnnnn\0")];
char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")];
- char *argv[] = { "uml_net", version_buf, "slip", "up", gate_buf,
+ char *argv[] = { "uml_net", version_buf, "slip", "up", gate_buf,
NULL };
int sfd, mfd, err;
err = get_pty();
- if(err < 0){
- printk("slip-open : Failed to open pty, err = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "slip-open : Failed to open pty, err = %d\n",
+ -err);
goto out;
}
mfd = err;
- err = os_open_file(ptsname(mfd), of_rdwr(OPENFLAGS()), 0);
- if(err < 0){
- printk("Couldn't open tty for slip line, err = %d\n", -err);
+ err = open(ptsname(mfd), O_RDWR, 0);
+ if (err < 0) {
+ printk(UM_KERN_ERR "Couldn't open tty for slip line, "
+ "err = %d\n", -err);
goto out_close;
}
sfd = err;
- if(set_up_tty(sfd))
+ if (set_up_tty(sfd))
goto out_close2;
pri->slave = sfd;
pri->slip.pos = 0;
pri->slip.esc = 0;
- if(pri->gate_addr != NULL){
+ if (pri->gate_addr != NULL) {
sprintf(version_buf, "%d", UML_NET_VERSION);
strcpy(gate_buf, pri->gate_addr);
err = slip_tramp(argv, sfd);
- if(err < 0){
- printk("slip_tramp failed - err = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "slip_tramp failed - err = %d\n",
+ -err);
goto out_close2;
}
err = os_get_ifname(pri->slave, pri->name);
- if(err < 0){
- printk("get_ifname failed, err = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "get_ifname failed, err = %d\n",
+ -err);
goto out_close2;
}
iter_addresses(pri->dev, open_addr, pri->name);
}
else {
err = os_set_slip(sfd);
- if(err < 0){
- printk("Failed to set slip discipline encapsulation - "
- "err = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "Failed to set slip discipline "
+ "encapsulation - err = %d\n", -err);
goto out_close2;
}
}
- return(mfd);
+ return mfd;
out_close2:
- os_close_file(sfd);
+ close(sfd);
out_close:
- os_close_file(mfd);
+ close(mfd);
out:
return err;
}
@@ -192,21 +202,21 @@ static void slip_close(int fd, void *data)
{
struct slip_data *pri = data;
char version_buf[sizeof("nnnnn\0")];
- char *argv[] = { "uml_net", version_buf, "slip", "down", pri->name,
+ char *argv[] = { "uml_net", version_buf, "slip", "down", pri->name,
NULL };
int err;
- if(pri->gate_addr != NULL)
+ if (pri->gate_addr != NULL)
iter_addresses(pri->dev, close_addr, pri->name);
sprintf(version_buf, "%d", UML_NET_VERSION);
err = slip_tramp(argv, pri->slave);
- if(err != 0)
- printk("slip_tramp failed - errno = %d\n", -err);
- os_close_file(fd);
- os_close_file(pri->slave);
+ if (err != 0)
+ printk(UM_KERN_ERR "slip_tramp failed - errno = %d\n", -err);
+ close(fd);
+ close(pri->slave);
pri->slave = -1;
}
@@ -220,17 +230,13 @@ int slip_user_write(int fd, void *buf, int len, struct slip_data *pri)
return slip_proto_write(fd, buf, len, &pri->slip);
}
-static int slip_set_mtu(int mtu, void *data)
-{
- return(mtu);
-}
-
static void slip_add_addr(unsigned char *addr, unsigned char *netmask,
void *data)
{
struct slip_data *pri = data;
- if(pri->slave < 0) return;
+ if (pri->slave < 0)
+ return;
open_addr(addr, netmask, pri->name);
}
@@ -239,7 +245,8 @@ static void slip_del_addr(unsigned char *addr, unsigned char *netmask,
{
struct slip_data *pri = data;
- if(pri->slave < 0) return;
+ if (pri->slave < 0)
+ return;
close_addr(addr, netmask, pri->name);
}
@@ -248,8 +255,8 @@ const struct net_user_info slip_user_info = {
.open = slip_open,
.close = slip_close,
.remove = NULL,
- .set_mtu = slip_set_mtu,
.add_address = slip_add_addr,
.delete_address = slip_del_addr,
- .max_packet = BUF_SIZE
+ .mtu = BUF_SIZE,
+ .max_packet = BUF_SIZE,
};
diff --git a/arch/um/drivers/slirp_kern.c b/arch/um/drivers/slirp_kern.c
index 0a0324a6d290..240ee650865d 100644
--- a/arch/um/drivers/slirp_kern.c
+++ b/arch/um/drivers/slirp_kern.c
@@ -1,11 +1,14 @@
-#include "linux/kernel.h"
-#include "linux/stddef.h"
+/*
+ * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Licensed under the GPL.
+ */
+
+#include <linux/if_arp.h>
#include "linux/init.h"
-#include "linux/netdevice.h"
-#include "linux/if_arp.h"
+#include <linux/netdevice.h>
+#include <linux/string.h>
#include "net_kern.h"
#include "net_user.h"
-#include "kern.h"
#include "slirp.h"
struct slirp_init {
@@ -39,29 +42,26 @@ void slirp_init(struct net_device *dev, void *data)
dev->tx_queue_len = 256;
dev->flags = IFF_NOARP;
printk("SLIRP backend - command line:");
- for(i=0;spri->argw.argv[i]!=NULL;i++) {
+ for (i = 0; spri->argw.argv[i] != NULL; i++)
printk(" '%s'",spri->argw.argv[i]);
- }
printk("\n");
}
static unsigned short slirp_protocol(struct sk_buff *skbuff)
{
- return(htons(ETH_P_IP));
+ return htons(ETH_P_IP);
}
-static int slirp_read(int fd, struct sk_buff **skb,
- struct uml_net_private *lp)
+static int slirp_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- return(slirp_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
- (struct slirp_data *) &lp->user));
+ return slirp_user_read(fd, skb_mac_header(skb), skb->dev->mtu,
+ (struct slirp_data *) &lp->user);
}
-static int slirp_write(int fd, struct sk_buff **skb,
- struct uml_net_private *lp)
+static int slirp_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
- return(slirp_user_write(fd, (*skb)->data, (*skb)->len,
- (struct slirp_data *) &lp->user));
+ return slirp_user_write(fd, skb->data, skb->len,
+ (struct slirp_data *) &lp->user);
}
const struct net_kern_info slirp_kern_info = {
@@ -76,31 +76,32 @@ static int slirp_setup(char *str, char **mac_out, void *data)
struct slirp_init *init = data;
int i=0;
- *init = ((struct slirp_init)
- { .argw = { { "slirp", NULL } } });
+ *init = ((struct slirp_init) { .argw = { { "slirp", NULL } } });
str = split_if_spec(str, mac_out, NULL);
- if(str == NULL) { /* no command line given after MAC addr */
- return(1);
- }
+ if (str == NULL) /* no command line given after MAC addr */
+ return 1;
do {
- if(i>=SLIRP_MAX_ARGS-1) {
- printk("slirp_setup: truncating slirp arguments\n");
+ if (i >= SLIRP_MAX_ARGS - 1) {
+ printk(KERN_WARNING "slirp_setup: truncating slirp "
+ "arguments\n");
break;
}
init->argw.argv[i++] = str;
while(*str && *str!=',') {
- if(*str=='_') *str=' ';
+ if (*str == '_')
+ *str=' ';
str++;
}
- if(*str!=',')
+ if (*str != ',')
break;
- *str++='\0';
- } while(1);
- init->argw.argv[i]=NULL;
- return(1);
+ *str++ = '\0';
+ } while (1);
+
+ init->argw.argv[i] = NULL;
+ return 1;
}
static struct transport slirp_transport = {
diff --git a/arch/um/drivers/slirp_user.c b/arch/um/drivers/slirp_user.c
index 0e462f64f227..1865089ff41a 100644
--- a/arch/um/drivers/slirp_user.c
+++ b/arch/um/drivers/slirp_user.c
@@ -1,18 +1,17 @@
-#include <stdio.h>
-#include <stdlib.h>
+/*
+ * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Licensed under the GPL.
+ */
+
#include <unistd.h>
-#include <stddef.h>
-#include <sched.h>
-#include <string.h>
#include <errno.h>
+#include <string.h>
#include <sys/wait.h>
-#include <sys/signal.h>
-#include "kern_util.h"
-#include "user.h"
+#include "kern_constants.h"
#include "net_user.h"
-#include "slirp.h"
-#include "slip_common.h"
#include "os.h"
+#include "slirp.h"
+#include "user.h"
static int slirp_user_init(void *data, void *dev)
{
@@ -31,8 +30,10 @@ static void slirp_pre_exec(void *arg)
{
struct slirp_pre_exec_data *data = arg;
- if(data->stdin != -1) dup2(data->stdin, 0);
- if(data->stdout != -1) dup2(data->stdout, 1);
+ if (data->stdin != -1)
+ dup2(data->stdin, 0);
+ if (data->stdout != -1)
+ dup2(data->stdout, 1);
}
static int slirp_tramp(char **argv, int fd)
@@ -44,7 +45,7 @@ static int slirp_tramp(char **argv, int fd)
pe_data.stdout = fd;
pid = run_helper(slirp_pre_exec, &pe_data, argv);
- return(pid);
+ return pid;
}
static int slirp_open(void *data)
@@ -53,12 +54,12 @@ static int slirp_open(void *data)
int fds[2], pid, err;
err = os_pipe(fds, 1, 1);
- if(err)
- return(err);
+ if (err)
+ return err;
err = slirp_tramp(pri->argw.argv, fds[1]);
- if(err < 0){
- printk("slirp_tramp failed - errno = %d\n", -err);
+ if (err < 0) {
+ printk(UM_KERN_ERR "slirp_tramp failed - errno = %d\n", -err);
goto out;
}
pid = err;
@@ -68,10 +69,10 @@ static int slirp_open(void *data)
pri->slip.esc = 0;
pri->pid = err;
- return(fds[0]);
+ return fds[0];
out:
- os_close_file(fds[0]);
- os_close_file(fds[1]);
+ close(fds[0]);
+ close(fds[1]);
return err;
}
@@ -80,31 +81,33 @@ static void slirp_close(int fd, void *data)
struct slirp_data *pri = data;
int status,err;
- os_close_file(fd);
- os_close_file(pri->slave);
+ close(fd);
+ close(pri->slave);
pri->slave = -1;
- if(pri->pid<1) {
- printk("slirp_close: no child process to shut down\n");
+ if (pri->pid<1) {
+ printk(UM_KERN_ERR "slirp_close: no child process to shut "
+ "down\n");
return;
}
#if 0
- if(kill(pri->pid, SIGHUP)<0) {
- printk("slirp_close: sending hangup to %d failed (%d)\n",
- pri->pid, errno);
+ if (kill(pri->pid, SIGHUP)<0) {
+ printk(UM_KERN_ERR "slirp_close: sending hangup to %d failed "
+ "(%d)\n", pri->pid, errno);
}
#endif
CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG));
- if(err < 0) {
- printk("slirp_close: waitpid returned %d\n", errno);
+ if (err < 0) {
+ printk(UM_KERN_ERR "slirp_close: waitpid returned %d\n", errno);
return;
}
- if(err == 0) {
- printk("slirp_close: process %d has not exited\n", pri->pid);
+ if (err == 0) {
+ printk(UM_KERN_ERR "slirp_close: process %d has not exited\n",
+ pri->pid);
return;
}
@@ -121,18 +124,13 @@ int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
return slip_proto_write(fd, buf, len, &pri->slip);
}
-static int slirp_set_mtu(int mtu, void *data)
-{
- return(mtu);
-}
-
const struct net_user_info slirp_user_info = {
.init = slirp_user_init,
.open = slirp_open,
.close = slirp_close,
.remove = NULL,
- .set_mtu = slirp_set_mtu,
.add_address = NULL,
.delete_address = NULL,
- .max_packet = BUF_SIZE
+ .mtu = BUF_SIZE,
+ .max_packet = BUF_SIZE,
};
diff --git a/arch/um/drivers/tty.c b/arch/um/drivers/tty.c
index a9f87e19c5bf..c930fedc5172 100644
--- a/arch/um/drivers/tty.c
+++ b/arch/um/drivers/tty.c
@@ -1,16 +1,16 @@
/*
- * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
+ * 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, int device, const struct chan_opts *opts)
{
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 output, int primary, void *d,
char **dev_out)
{
struct tty_chan *data = d;
- int fd, err;
+ int fd, err, mode = 0;
+
+ if (input && output)
+ mode = O_RDWR;
+ else if (input)
+ mode = O_RDONLY;
+ else if (output)
+ mode = O_WRONLY;
- fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0);
- if(fd < 0)
- return fd;
+ 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;
}
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 0eabe73c964d..25b248a02507 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -615,7 +615,7 @@ static int ubd_open_dev(struct ubd *ubd_dev)
blk_queue_max_sectors(ubd_dev->queue, 8 * sizeof(long));
err = -ENOMEM;
- ubd_dev->cow.bitmap = (void *) vmalloc(ubd_dev->cow.bitmap_len);
+ ubd_dev->cow.bitmap = vmalloc(ubd_dev->cow.bitmap_len);
if(ubd_dev->cow.bitmap == NULL){
printk(KERN_ERR "Failed to vmalloc COW bitmap\n");
goto error;
diff --git a/arch/um/drivers/vde.h b/arch/um/drivers/vde.h
new file mode 100644
index 000000000000..fc3a05902ba1
--- /dev/null
+++ b/arch/um/drivers/vde.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2007 Luca Bigliardi (shammash@artha.org).
+ * Licensed under the GPL.
+ */
+
+#ifndef __UM_VDE_H__
+#define __UM_VDE_H__
+
+struct vde_data {
+ char *vde_switch;
+ char *descr;
+ void *args;
+ void *conn;
+ void *dev;
+};
+
+struct vde_init {
+ char *vde_switch;
+ char *descr;
+ int port;
+ char *group;
+ int mode;
+};
+
+extern const struct net_user_info vde_user_info;
+
+extern void vde_init_libstuff(struct vde_data *vpri, struct vde_init *init);
+
+extern int vde_user_read(void *conn, void *buf, int len);
+extern int vde_user_write(void *conn, void *buf, int len);
+
+#endif
diff --git a/arch/um/drivers/vde_kern.c b/arch/um/drivers/vde_kern.c
new file mode 100644
index 000000000000..add7e722defb
--- /dev/null
+++ b/arch/um/drivers/vde_kern.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2007 Luca Bigliardi (shammash@artha.org).
+ * Licensed under the GPL.
+ *
+ * Transport usage:
+ * ethN=vde,<vde_switch>,<mac addr>,<port>,<group>,<mode>,<description>
+ *
+ */
+
+#include "linux/init.h"
+#include <linux/netdevice.h>
+#include "net_kern.h"
+#include "net_user.h"
+#include "vde.h"
+
+static void vde_init(struct net_device *dev, void *data)
+{
+ struct vde_init *init = data;
+ struct uml_net_private *pri;
+ struct vde_data *vpri;
+
+ pri = dev->priv;
+ vpri = (struct vde_data *) pri->user;
+
+ vpri->vde_switch = init->vde_switch;
+ vpri->descr = init->descr ? init->descr : "UML vde_transport";
+ vpri->args = NULL;
+ vpri->conn = NULL;
+ vpri->dev = dev;
+
+ printk("vde backend - %s, ", vpri->vde_switch ?
+ vpri->vde_switch : "(default socket)");
+
+ vde_init_libstuff(vpri, init);
+
+ printk("\n");
+}
+
+static int vde_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
+{
+ struct vde_data *pri = (struct vde_data *) &lp->user;
+
+ if (pri->conn != NULL)
+ return vde_user_read(pri->conn, skb_mac_header(skb),
+ skb->dev->mtu + ETH_HEADER_OTHER);
+
+ printk(KERN_ERR "vde_read - we have no VDECONN to read from");
+ return -EBADF;
+}
+
+static int vde_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
+{
+ struct vde_data *pri = (struct vde_data *) &lp->user;
+
+ if (pri->conn != NULL)
+ return vde_user_write((void *)pri->conn, skb->data,
+ skb->len);
+
+ printk(KERN_ERR "vde_write - we have no VDECONN to write to");
+ return -EBADF;
+}
+
+static const struct net_kern_info vde_kern_info = {
+ .init = vde_init,
+ .protocol = eth_protocol,
+ .read = vde_read,
+ .write = vde_write,
+};
+
+static int vde_setup(char *str, char **mac_out, void *data)
+{
+ struct vde_init *init = data;
+ char *remain, *port_str = NULL, *mode_str = NULL, *last;
+
+ *init = ((struct vde_init)
+ { .vde_switch = NULL,
+ .descr = NULL,
+ .port = 0,
+ .group = NULL,
+ .mode = 0 });
+
+ remain = split_if_spec(str, &init->vde_switch, mac_out, &port_str,
+ &init->group, &mode_str, &init->descr, NULL);
+
+ if (remain != NULL)
+ printk(KERN_WARNING "vde_setup - Ignoring extra data :"
+ "'%s'\n", remain);
+
+ if (port_str != NULL) {
+ init->port = simple_strtoul(port_str, &last, 10);
+ if ((*last != '\0') || (last == port_str)) {
+ printk(KERN_ERR "vde_setup - Bad port : '%s'\n",
+ port_str);
+ return 0;
+ }
+ }
+
+ if (mode_str != NULL) {
+ init->mode = simple_strtoul(mode_str, &last, 8);
+ if ((*last != '\0') || (last == mode_str)) {
+ printk(KERN_ERR "vde_setup - Bad mode : '%s'\n",
+ mode_str);
+ return 0;
+ }
+ }
+
+ printk(KERN_INFO "Configured vde device: %s\n", init->vde_switch ?
+ init->vde_switch : "(default socket)");
+
+ return 1;
+}
+
+static struct transport vde_transport = {
+ .list = LIST_HEAD_INIT(vde_transport.list),
+ .name = "vde",
+ .setup = vde_setup,
+ .user = &vde_user_info,
+ .kern = &vde_kern_info,
+ .private_size = sizeof(struct vde_data),
+ .setup_size = sizeof(struct vde_init),
+};
+
+static int register_vde(void)
+{
+ register_transport(&vde_transport);
+ return 0;
+}
+
+late_initcall(register_vde);
diff --git a/arch/um/drivers/vde_user.c b/arch/um/drivers/vde_user.c
new file mode 100644
index 000000000000..d9941fe5f931
--- /dev/null
+++ b/arch/um/drivers/vde_user.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2007 Luca Bigliardi (shammash@artha.org).
+ * Licensed under the GPL.
+ */
+
+#include <stddef.h>
+#include <errno.h>
+#include <libvdeplug.h>
+#include "kern_constants.h"
+#include "net_user.h"
+#include "um_malloc.h"
+#include "user.h"
+#include "vde.h"
+
+static int vde_user_init(void *data, void *dev)
+{
+ struct vde_data *pri = data;
+ VDECONN *conn = NULL;
+ int err = -EINVAL;
+
+ pri->dev = dev;
+
+ conn = vde_open(pri->vde_switch, pri->descr, pri->args);
+
+ if (conn == NULL) {
+ err = -errno;
+ printk(UM_KERN_ERR "vde_user_init: vde_open failed, "
+ "errno = %d\n", errno);
+ return err;
+ }
+
+ printk(UM_KERN_INFO "vde backend - connection opened\n");
+
+ pri->conn = conn;
+
+ return 0;
+}
+
+static int vde_user_open(void *data)
+{
+ struct vde_data *pri = data;
+
+ if (pri->conn != NULL)
+ return vde_datafd(pri->conn);
+
+ printk(UM_KERN_WARNING "vde_open - we have no VDECONN to open");
+ return -EINVAL;
+}
+
+static void vde_remove(void *data)
+{
+ struct vde_data *pri = data;
+
+ if (pri->conn != NULL) {
+ printk(UM_KERN_INFO "vde backend - closing connection\n");
+ vde_close(pri->conn);
+ pri->conn = NULL;
+ kfree(pri->args);
+ pri->args = NULL;
+ return;
+ }
+
+ printk(UM_KERN_WARNING "vde_remove - we have no VDECONN to remove");
+}
+
+const struct net_user_info vde_user_info = {
+ .init = vde_user_init,
+ .open = vde_user_open,
+ .close = NULL,
+ .remove = vde_remove,
+ .add_address = NULL,
+ .delete_address = NULL,
+ .mtu = ETH_MAX_PACKET,
+ .max_packet = ETH_MAX_PACKET + ETH_HEADER_OTHER,
+};
+
+void vde_init_libstuff(struct vde_data *vpri, struct vde_init *init)
+{
+ struct vde_open_args *args;
+
+ vpri->args = kmalloc(sizeof(struct vde_open_args), UM_GFP_KERNEL);
+ if (vpri->args == NULL) {
+ printk(UM_KERN_ERR "vde_init_libstuff - vde_open_args"
+ "allocation failed");
+ return;
+ }
+
+ args = vpri->args;
+
+ args->port = init->port;
+ args->group = init->group;
+ args->mode = init->mode ? init->mode : 0700;
+
+ args->port ? printk(UM_KERN_INFO "port %d", args->port) :
+ printk(UM_KERN_INFO "undefined port");
+}
+
+int vde_user_read(void *conn, void *buf, int len)
+{
+ VDECONN *vconn = conn;
+ int rv;
+
+ if (vconn == NULL)
+ return 0;
+
+ rv = vde_recv(vconn, buf, len, 0);
+ if (rv < 0) {
+ if (errno == EAGAIN)
+ return 0;
+ return -errno;
+ }
+ else if (rv == 0)
+ return -ENOTCONN;
+
+ return rv;
+}
+
+int vde_user_write(void *conn, void *buf, int len)
+{
+ VDECONN *vconn = conn;
+
+ if (vconn == NULL)
+ return 0;
+
+ return vde_send(vconn, buf, len, 0);
+}
+
diff --git a/arch/um/drivers/xterm.c b/arch/um/drivers/xterm.c
index fd817e541543..8a1c18a9b240 100644
--- a/arch/um/drivers/xterm.c
+++ b/arch/um/drivers/xterm.c
@@ -1,20 +1,21 @@
-/*
+/*
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
-#include <stdlib.h>
+#include <stddef.h>
#include <stdio.h>
+#include <stdlib.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 device, const struct chan_opts *opts)
{
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,
@@ -95,8 +96,10 @@ static int xterm_open(int input, int output, int primary, void *d,
if (access(argv[4], X_OK) < 0)
argv[4] = "port-helper";
- /* Check that DISPLAY is set, this doesn't guarantee the xterm
- * will work but w/o it we can be pretty sure it won't. */
+ /*
+ * Check that DISPLAY is set, this doesn't guarantee the xterm
+ * will work but w/o it we can be pretty sure it won't.
+ */
if (getenv("DISPLAY") == NULL) {
printk(UM_KERN_ERR "xterm_open: $DISPLAY not set.\n");
return -ENODEV;
@@ -195,7 +198,7 @@ static int xterm_open(int input, int output, int primary, void *d,
static void xterm_close(int fd, void *d)
{
struct xterm_chan *data = d;
-
+
if (data->pid != -1)
os_kill_process(data->pid, 1);
data->pid = -1;
@@ -207,11 +210,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 +219,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,
};