2006-02-21 17:18:48

by Blaisorblade

[permalink] [raw]
Subject: [PATCH 0/6] UML little patches for 2.6.16

I'm sending some little fixups for inclusion 2.6.16. I've held some other
fixes which need wider testing. Please merge now.

--
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade


2006-02-21 17:17:24

by Blaisorblade

[permalink] [raw]
Subject: [PATCH 6/6] uml: tidying COW code


Improve (especially for coherence) some prototypes, and return code of
init_cow_file in error case - for a short write return -EINVAL, otherwise return
the error we got!

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <[email protected]>
---

arch/um/drivers/cow.h | 2 +-
arch/um/drivers/cow_sys.h | 4 ++--
arch/um/drivers/cow_user.c | 3 ++-
arch/um/drivers/ubd_kern.c | 2 +-
4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/um/drivers/cow.h b/arch/um/drivers/cow.h
index dc36b22..04e3958 100644
--- a/arch/um/drivers/cow.h
+++ b/arch/um/drivers/cow.h
@@ -46,7 +46,7 @@ extern int file_reader(__u64 offset, cha
extern int read_cow_header(int (*reader)(__u64, char *, int, void *),
void *arg, __u32 *version_out,
char **backing_file_out, time_t *mtime_out,
- unsigned long long *size_out, int *sectorsize_out,
+ __u64 *size_out, int *sectorsize_out,
__u32 *align_out, int *bitmap_offset_out);

extern int write_cow_header(char *cow_file, int fd, char *backing_file,
diff --git a/arch/um/drivers/cow_sys.h b/arch/um/drivers/cow_sys.h
index df25263..94de4ea 100644
--- a/arch/um/drivers/cow_sys.h
+++ b/arch/um/drivers/cow_sys.h
@@ -23,12 +23,12 @@ static inline char *cow_strdup(char *str
return(uml_strdup(str));
}

-static inline int cow_seek_file(int fd, unsigned long long offset)
+static inline int cow_seek_file(int fd, __u64 offset)
{
return(os_seek_file(fd, offset));
}

-static inline int cow_file_size(char *file, unsigned long long *size_out)
+static inline int cow_file_size(char *file, __u64 *size_out)
{
return(os_file_size(file, size_out));
}
diff --git a/arch/um/drivers/cow_user.c b/arch/um/drivers/cow_user.c
index d1c86bc..61951b7 100644
--- a/arch/um/drivers/cow_user.c
+++ b/arch/um/drivers/cow_user.c
@@ -362,7 +362,8 @@ int init_cow_file(int fd, char *cow_file
if(err != sizeof(zero)){
cow_printf("Write of bitmap to new COW file '%s' failed, "
"err = %d\n", cow_file, -err);
- err = -EINVAL;
+ if (err >= 0)
+ err = -EINVAL;
goto out;
}

diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index f93af66..59f9890 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1141,7 +1141,7 @@ static int path_requires_switch(char *fr
static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
{
unsigned long modtime;
- long long actual;
+ unsigned long long actual;
int err;

err = os_file_modtime(file, &modtime);

2006-02-21 17:17:24

by Blaisorblade

[permalink] [raw]
Subject: [PATCH 4/6] uml: os_connect_socket error path fixup


Fix an fd leak and a return of -1 instead of -errno in the error path - this
showed up in intensive testing of HPPFS, the os_connect_socket user.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <[email protected]>
---

arch/um/os-Linux/file.c | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index f55773c..3bd10de 100644
--- a/arch/um/os-Linux/file.c
+++ b/arch/um/os-Linux/file.c
@@ -272,14 +272,23 @@ int os_connect_socket(char *name)
snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name);

fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if(fd < 0)
- return(fd);
+ if(fd < 0) {
+ err = -errno;
+ goto out;
+ }

err = connect(fd, (struct sockaddr *) &sock, sizeof(sock));
- if(err)
- return(-errno);
+ if(err) {
+ err = -errno;
+ goto out_close;
+ }

- return(fd);
+ return fd;
+
+out_close:
+ close(fd);
+out:
+ return err;
}

void os_close_file(int fd)

2006-02-21 17:17:49

by Blaisorblade

[permalink] [raw]
Subject: [PATCH 1/6] uml: correct error messages in COW driver


Improve some error messages in the COW driver, and say V3, not V2, when talking
about V3 format. Also resync with our userspace code utility a bit more.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <[email protected]>
---

arch/um/drivers/cow_sys.h | 2 +-
arch/um/drivers/cow_user.c | 21 ++++++++++++---------
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/um/drivers/cow_sys.h b/arch/um/drivers/cow_sys.h
index c83fc5d..df25263 100644
--- a/arch/um/drivers/cow_sys.h
+++ b/arch/um/drivers/cow_sys.h
@@ -33,7 +33,7 @@ static inline int cow_file_size(char *fi
return(os_file_size(file, size_out));
}

-static inline int cow_write_file(int fd, char *buf, int size)
+static inline int cow_write_file(int fd, void *buf, int size)
{
return(os_write_file(fd, buf, size));
}
diff --git a/arch/um/drivers/cow_user.c b/arch/um/drivers/cow_user.c
index fbe2217..d1c86bc 100644
--- a/arch/um/drivers/cow_user.c
+++ b/arch/um/drivers/cow_user.c
@@ -176,7 +176,7 @@ int write_cow_header(char *cow_file, int
err = -ENOMEM;
header = cow_malloc(sizeof(*header));
if(header == NULL){
- cow_printf("Failed to allocate COW V3 header\n");
+ cow_printf("write_cow_header - failed to allocate COW V3 header\n");
goto out;
}
header->magic = htonl(COW_MAGIC);
@@ -196,15 +196,17 @@ int write_cow_header(char *cow_file, int

err = os_file_modtime(header->backing_file, &modtime);
if(err < 0){
- cow_printf("Backing file '%s' mtime request failed, "
- "err = %d\n", header->backing_file, -err);
+ cow_printf("write_cow_header - backing file '%s' mtime "
+ "request failed, err = %d\n", header->backing_file,
+ -err);
goto out_free;
}

err = cow_file_size(header->backing_file, size);
if(err < 0){
- cow_printf("Couldn't get size of backing file '%s', "
- "err = %d\n", header->backing_file, -err);
+ cow_printf("write_cow_header - couldn't get size of "
+ "backing file '%s', err = %d\n",
+ header->backing_file, -err);
goto out_free;
}

@@ -214,10 +216,11 @@ int write_cow_header(char *cow_file, int
header->alignment = htonl(alignment);
header->cow_format = COW_BITMAP;

- err = os_write_file(fd, header, sizeof(*header));
+ err = cow_write_file(fd, header, sizeof(*header));
if(err != sizeof(*header)){
- cow_printf("Write of header to new COW file '%s' failed, "
- "err = %d\n", cow_file, -err);
+ cow_printf("write_cow_header - write of header to "
+ "new COW file '%s' failed, err = %d\n", cow_file,
+ -err);
goto out_free;
}
err = 0;
@@ -299,7 +302,7 @@ int read_cow_header(int (*reader)(__u64,
}
else if(version == 3){
if(n < sizeof(header->v3)){
- cow_printf("read_cow_header - failed to read V2 "
+ cow_printf("read_cow_header - failed to read V3 "
"header\n");
goto out;
}

2006-02-21 17:17:49

by Blaisorblade

[permalink] [raw]
Subject: [PATCH 2/6] uml: fix usage of kernel_errno in place of errno


From: Paolo 'Blaisorblade' Giarrusso <[email protected]>

To avoid conflicts, in kernel files errno is expanded to kernel_errno, to
distinguish it from glibc errno. In this case, the code wants to use the libc
errno but the kernel one is used; in the other usage, we return errno in place
of -errno in case of an error.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <[email protected]>
---

arch/um/include/os.h | 3 +++
arch/um/os-Linux/process.c | 15 +++++++++++++++
arch/um/sys-i386/ldt.c | 9 +++------
3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/arch/um/include/os.h b/arch/um/include/os.h
index eb1710b..2a1c64d 100644
--- a/arch/um/include/os.h
+++ b/arch/um/include/os.h
@@ -179,8 +179,11 @@ extern void os_stop_process(int pid);
extern void os_kill_process(int pid, int reap_child);
extern void os_kill_ptraced_process(int pid, int reap_child);
extern void os_usr1_process(int pid);
+extern long os_ptrace_ldt(long pid, long addr, long data);
+
extern int os_getpid(void);
extern int os_getpgrp(void);
+
extern void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int));
extern void init_new_thread_signals(int altstack);
extern int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr);
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c
index 7f5e2da..49434a7 100644
--- a/arch/um/os-Linux/process.c
+++ b/arch/um/os-Linux/process.c
@@ -19,6 +19,7 @@
#include "irq_user.h"
#include "kern_util.h"
#include "longjmp.h"
+#include "skas_ptrace.h"

#define ARBITRARY_ADDR -1
#define FAILURE_PID -1
@@ -100,6 +101,20 @@ void os_kill_process(int pid, int reap_c

}

+/* This is here uniquely to have access to the userspace errno, i.e. the one
+ * used by ptrace in case of error.
+ */
+
+long os_ptrace_ldt(long pid, long addr, long data) {
+ int ret;
+
+ ret = ptrace(PTRACE_LDT, pid, addr, data);
+
+ if (ret < 0)
+ return -errno;
+ return ret;
+}
+
/* Kill off a ptraced child by all means available. kill it normally first,
* then PTRACE_KILL it, then PTRACE_CONT it in case it's in a run state from
* which it can't exit directly.
diff --git a/arch/um/sys-i386/ldt.c b/arch/um/sys-i386/ldt.c
index 1fa09a7..fe0877b 100644
--- a/arch/um/sys-i386/ldt.c
+++ b/arch/um/sys-i386/ldt.c
@@ -107,7 +107,7 @@ long write_ldt_entry(struct mm_id * mm_i
* So we need to switch child's mm into our userspace, then
* later switch back.
*
- * Note: I'm unshure: should interrupts be disabled here?
+ * Note: I'm unsure: should interrupts be disabled here?
*/
if(!current->active_mm || current->active_mm == &init_mm ||
mm_idp != &current->active_mm->context.skas.id)
@@ -129,9 +129,7 @@ long write_ldt_entry(struct mm_id * mm_i
pid = userspace_pid[cpu];
}

- res = ptrace(PTRACE_LDT, pid, 0, (unsigned long) &ldt_op);
- if(res)
- res = errno;
+ res = os_ptrace_ldt(pid, 0, (unsigned long) &ldt_op);

if(proc_mm)
put_cpu();
@@ -181,8 +179,7 @@ static long read_ldt_from_host(void __us
*/

cpu = get_cpu();
- res = ptrace(PTRACE_LDT, userspace_pid[cpu], 0,
- (unsigned long) &ptrace_ldt);
+ res = os_ptrace_ldt(userspace_pid[cpu], 0, (unsigned long) &ptrace_ldt);
put_cpu();
if(res < 0)
goto out;

2006-02-21 17:18:05

by Blaisorblade

[permalink] [raw]
Subject: [PATCH 5/6] uml: better error reporting for read_output


Do precise error handling: print precise error messages, distinguishing short
reads and read errors. This functions fails frequently enough for me so I
bothered doing this fix.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <[email protected]>
---

arch/um/drivers/net_user.c | 34 ++++++++++++++++++++++------------
1 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/arch/um/drivers/net_user.c b/arch/um/drivers/net_user.c
index 098fa65..0e2f061 100644
--- a/arch/um/drivers/net_user.c
+++ b/arch/um/drivers/net_user.c
@@ -47,10 +47,12 @@ void tap_check_ips(char *gate_addr, unsi
}
}

+/* Do reliable error handling as this fails frequently enough. */
void read_output(int fd, char *output, int len)
{
- int remain, n, actual;
+ int remain, ret, expected;
char c;
+ char *str;

if(output == NULL){
output = &c;
@@ -58,23 +60,31 @@ void read_output(int fd, char *output, i
}

*output = '\0';
- n = os_read_file(fd, &remain, sizeof(remain));
- if(n != sizeof(remain)){
- printk("read_output - read of length failed, err = %d\n", -n);
- return;
+ ret = os_read_file(fd, &remain, sizeof(remain));
+
+ if (ret != sizeof(remain)) {
+ expected = sizeof(remain);
+ str = "length";
+ goto err;
}

while(remain != 0){
- n = (remain < len) ? remain : len;
- actual = os_read_file(fd, output, n);
- if(actual != n){
- printk("read_output - read of data failed, "
- "err = %d\n", -actual);
- return;
+ expected = (remain < len) ? remain : len;
+ ret = os_read_file(fd, output, expected);
+ if (ret != expected) {
+ str = "data";
+ goto err;
}
- remain -= actual;
+ remain -= ret;
}
+
return;
+
+err:
+ if (ret < 0)
+ printk("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);
}

int net_read(int fd, void *buf, int len)

2006-02-21 17:18:51

by Blaisorblade

[permalink] [raw]
Subject: [PATCH 3/6] uml: fix ((unused)) attribute


Use __attribute_used__ instead of __attribute__ ((unused)).
This will help with GCC > 3.2.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <[email protected]>
---

arch/um/include/init.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/um/include/init.h b/arch/um/include/init.h
index cbd79a8..d4de7c0 100644
--- a/arch/um/include/init.h
+++ b/arch/um/include/init.h
@@ -122,7 +122,7 @@ extern struct uml_param __uml_setup_star

#define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn

-#define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
+#define __init_call __attribute_used__ __attribute__ ((__section__ (".initcall.init")))

#endif


2006-02-21 20:48:19

by Jeff Dike

[permalink] [raw]
Subject: Re: [PATCH 0/6] UML little patches for 2.6.16

On Tue, Feb 21, 2006 at 06:15:35PM +0100, Paolo 'Blaisorblade' Giarrusso wrote:
> I'm sending some little fixups for inclusion 2.6.16. I've held some other
> fixes which need wider testing. Please merge now.

Acked-by: Jeff Dike <[email protected]>