diff options
author | Jeff Dike <jdike@addtoit.com> | 2007-07-23 21:43:47 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-24 15:24:58 -0400 |
commit | da3e30e78ed9652322dccb49fa149e7b4e985f74 (patch) | |
tree | f0d8556e419be265e645d0a6f5ead070ee0aded2 /arch/um/os-Linux | |
parent | 1a65f493c335abc3822291b52f3565776ce39a1b (diff) |
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>
Diffstat (limited to 'arch/um/os-Linux')
-rw-r--r-- | arch/um/os-Linux/aio.c | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c index b126df4ea168..59348359f9ab 100644 --- a/arch/um/os-Linux/aio.c +++ b/arch/um/os-Linux/aio.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "init.h" | 14 | #include "init.h" |
15 | #include "user.h" | 15 | #include "user.h" |
16 | #include "mode.h" | 16 | #include "mode.h" |
17 | #include "kern_constants.h" | ||
17 | 18 | ||
18 | struct aio_thread_req { | 19 | struct aio_thread_req { |
19 | enum aio_type type; | 20 | enum aio_type type; |
@@ -65,47 +66,33 @@ static long io_getevents(aio_context_t ctx_id, long min_nr, long nr, | |||
65 | static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf, | 66 | static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf, |
66 | int len, unsigned long long offset, struct aio_context *aio) | 67 | int len, unsigned long long offset, struct aio_context *aio) |
67 | { | 68 | { |
68 | struct iocb iocb, *iocbp = &iocb; | 69 | struct iocb *iocbp = & ((struct iocb) { |
70 | .aio_data = (unsigned long) aio, | ||
71 | .aio_fildes = fd, | ||
72 | .aio_buf = (unsigned long) buf, | ||
73 | .aio_nbytes = len, | ||
74 | .aio_offset = offset | ||
75 | }); | ||
69 | char c; | 76 | char c; |
70 | int err; | ||
71 | 77 | ||
72 | iocb = ((struct iocb) { .aio_data = (unsigned long) aio, | 78 | switch (type) { |
73 | .aio_reqprio = 0, | ||
74 | .aio_fildes = fd, | ||
75 | .aio_buf = (unsigned long) buf, | ||
76 | .aio_nbytes = len, | ||
77 | .aio_offset = offset, | ||
78 | .aio_reserved1 = 0, | ||
79 | .aio_reserved2 = 0, | ||
80 | .aio_reserved3 = 0 }); | ||
81 | |||
82 | switch(type){ | ||
83 | case AIO_READ: | 79 | case AIO_READ: |
84 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; | 80 | iocbp->aio_lio_opcode = IOCB_CMD_PREAD; |
85 | err = io_submit(ctx, 1, &iocbp); | ||
86 | break; | 81 | break; |
87 | case AIO_WRITE: | 82 | case AIO_WRITE: |
88 | iocb.aio_lio_opcode = IOCB_CMD_PWRITE; | 83 | iocbp->aio_lio_opcode = IOCB_CMD_PWRITE; |
89 | err = io_submit(ctx, 1, &iocbp); | ||
90 | break; | 84 | break; |
91 | case AIO_MMAP: | 85 | case AIO_MMAP: |
92 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; | 86 | iocbp->aio_lio_opcode = IOCB_CMD_PREAD; |
93 | iocb.aio_buf = (unsigned long) &c; | 87 | iocbp->aio_buf = (unsigned long) &c; |
94 | iocb.aio_nbytes = sizeof(c); | 88 | iocbp->aio_nbytes = sizeof(c); |
95 | err = io_submit(ctx, 1, &iocbp); | ||
96 | break; | 89 | break; |
97 | default: | 90 | default: |
98 | printk("Bogus op in do_aio - %d\n", type); | 91 | printk(UM_KERN_ERR "Bogus op in do_aio - %d\n", type); |
99 | err = -EINVAL; | 92 | return -EINVAL; |
100 | break; | ||
101 | } | 93 | } |
102 | 94 | ||
103 | if(err > 0) | 95 | return (io_submit(ctx, 1, &iocbp) > 0) ? 0 : -errno; |
104 | err = 0; | ||
105 | else | ||
106 | err = -errno; | ||
107 | |||
108 | return err; | ||
109 | } | 96 | } |
110 | 97 | ||
111 | /* Initialized in an initcall and unchanged thereafter */ | 98 | /* Initialized in an initcall and unchanged thereafter */ |