uml: fix aio compilation bug

Restructure do_aio thanks to commments from Ulrich and Al.

Uli started this by seeing that UML's initialization of a struct iocb
initialized fields that it shouldn't.

Al followed up by adding the following cleanups:
	eliminating a variable by just using an anonymous structure in
its place.
	hoisting a duplicated line out of the switch.
	simplifying the error checking at the end.

I added a severity to the printk.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Ulrich Drepper <drepper@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Jeff Dike 2007-07-23 18:43:47 -07:00 committed by Linus Torvalds
parent 1a65f493c3
commit da3e30e78e
1 changed files with 17 additions and 30 deletions

View File

@ -14,6 +14,7 @@
#include "init.h" #include "init.h"
#include "user.h" #include "user.h"
#include "mode.h" #include "mode.h"
#include "kern_constants.h"
struct aio_thread_req { struct aio_thread_req {
enum aio_type type; enum aio_type type;
@ -65,47 +66,33 @@ static long io_getevents(aio_context_t ctx_id, long min_nr, long nr,
static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf, static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf,
int len, unsigned long long offset, struct aio_context *aio) int len, unsigned long long offset, struct aio_context *aio)
{ {
struct iocb iocb, *iocbp = &iocb; struct iocb *iocbp = & ((struct iocb) {
char c; .aio_data = (unsigned long) aio,
int err;
iocb = ((struct iocb) { .aio_data = (unsigned long) aio,
.aio_reqprio = 0,
.aio_fildes = fd, .aio_fildes = fd,
.aio_buf = (unsigned long) buf, .aio_buf = (unsigned long) buf,
.aio_nbytes = len, .aio_nbytes = len,
.aio_offset = offset, .aio_offset = offset
.aio_reserved1 = 0, });
.aio_reserved2 = 0, char c;
.aio_reserved3 = 0 });
switch(type){ switch (type) {
case AIO_READ: case AIO_READ:
iocb.aio_lio_opcode = IOCB_CMD_PREAD; iocbp->aio_lio_opcode = IOCB_CMD_PREAD;
err = io_submit(ctx, 1, &iocbp);
break; break;
case AIO_WRITE: case AIO_WRITE:
iocb.aio_lio_opcode = IOCB_CMD_PWRITE; iocbp->aio_lio_opcode = IOCB_CMD_PWRITE;
err = io_submit(ctx, 1, &iocbp);
break; break;
case AIO_MMAP: case AIO_MMAP:
iocb.aio_lio_opcode = IOCB_CMD_PREAD; iocbp->aio_lio_opcode = IOCB_CMD_PREAD;
iocb.aio_buf = (unsigned long) &c; iocbp->aio_buf = (unsigned long) &c;
iocb.aio_nbytes = sizeof(c); iocbp->aio_nbytes = sizeof(c);
err = io_submit(ctx, 1, &iocbp);
break; break;
default: default:
printk("Bogus op in do_aio - %d\n", type); printk(UM_KERN_ERR "Bogus op in do_aio - %d\n", type);
err = -EINVAL; return -EINVAL;
break;
} }
if(err > 0) return (io_submit(ctx, 1, &iocbp) > 0) ? 0 : -errno;
err = 0;
else
err = -errno;
return err;
} }
/* Initialized in an initcall and unchanged thereafter */ /* Initialized in an initcall and unchanged thereafter */