diff options
Diffstat (limited to 'arch/um/os-Linux/aio.c')
-rw-r--r-- | arch/um/os-Linux/aio.c | 205 |
1 files changed, 94 insertions, 111 deletions
diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c index f6e64026f995..41cfb0944201 100644 --- a/arch/um/os-Linux/aio.c +++ b/arch/um/os-Linux/aio.c | |||
@@ -6,7 +6,6 @@ | |||
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | #include <unistd.h> | 7 | #include <unistd.h> |
8 | #include <signal.h> | 8 | #include <signal.h> |
9 | #include <string.h> | ||
10 | #include <errno.h> | 9 | #include <errno.h> |
11 | #include <sched.h> | 10 | #include <sched.h> |
12 | #include <sys/syscall.h> | 11 | #include <sys/syscall.h> |
@@ -17,31 +16,18 @@ | |||
17 | #include "user.h" | 16 | #include "user.h" |
18 | #include "mode.h" | 17 | #include "mode.h" |
19 | 18 | ||
19 | struct aio_thread_req { | ||
20 | enum aio_type type; | ||
21 | int io_fd; | ||
22 | unsigned long long offset; | ||
23 | char *buf; | ||
24 | int len; | ||
25 | struct aio_context *aio; | ||
26 | }; | ||
27 | |||
20 | static int aio_req_fd_r = -1; | 28 | static int aio_req_fd_r = -1; |
21 | static int aio_req_fd_w = -1; | 29 | static int aio_req_fd_w = -1; |
22 | 30 | ||
23 | static int update_aio(struct aio_context *aio, int res) | ||
24 | { | ||
25 | if(res < 0) | ||
26 | aio->len = res; | ||
27 | else if((res == 0) && (aio->type == AIO_READ)){ | ||
28 | /* This is the EOF case - we have hit the end of the file | ||
29 | * and it ends in a partial block, so we fill the end of | ||
30 | * the block with zeros and claim success. | ||
31 | */ | ||
32 | memset(aio->data, 0, aio->len); | ||
33 | aio->len = 0; | ||
34 | } | ||
35 | else if(res > 0){ | ||
36 | aio->len -= res; | ||
37 | aio->data += res; | ||
38 | aio->offset += res; | ||
39 | return aio->len; | ||
40 | } | ||
41 | |||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | #if defined(HAVE_AIO_ABI) | 31 | #if defined(HAVE_AIO_ABI) |
46 | #include <linux/aio_abi.h> | 32 | #include <linux/aio_abi.h> |
47 | 33 | ||
@@ -80,7 +66,8 @@ static long io_getevents(aio_context_t ctx_id, long min_nr, long nr, | |||
80 | * that it now backs the mmapped area. | 66 | * that it now backs the mmapped area. |
81 | */ | 67 | */ |
82 | 68 | ||
83 | static int do_aio(aio_context_t ctx, struct aio_context *aio) | 69 | static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf, |
70 | int len, unsigned long long offset, struct aio_context *aio) | ||
84 | { | 71 | { |
85 | struct iocb iocb, *iocbp = &iocb; | 72 | struct iocb iocb, *iocbp = &iocb; |
86 | char c; | 73 | char c; |
@@ -88,39 +75,40 @@ static int do_aio(aio_context_t ctx, struct aio_context *aio) | |||
88 | 75 | ||
89 | iocb = ((struct iocb) { .aio_data = (unsigned long) aio, | 76 | iocb = ((struct iocb) { .aio_data = (unsigned long) aio, |
90 | .aio_reqprio = 0, | 77 | .aio_reqprio = 0, |
91 | .aio_fildes = aio->fd, | 78 | .aio_fildes = fd, |
92 | .aio_buf = (unsigned long) aio->data, | 79 | .aio_buf = (unsigned long) buf, |
93 | .aio_nbytes = aio->len, | 80 | .aio_nbytes = len, |
94 | .aio_offset = aio->offset, | 81 | .aio_offset = offset, |
95 | .aio_reserved1 = 0, | 82 | .aio_reserved1 = 0, |
96 | .aio_reserved2 = 0, | 83 | .aio_reserved2 = 0, |
97 | .aio_reserved3 = 0 }); | 84 | .aio_reserved3 = 0 }); |
98 | 85 | ||
99 | switch(aio->type){ | 86 | switch(type){ |
100 | case AIO_READ: | 87 | case AIO_READ: |
101 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; | 88 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; |
89 | err = io_submit(ctx, 1, &iocbp); | ||
102 | break; | 90 | break; |
103 | case AIO_WRITE: | 91 | case AIO_WRITE: |
104 | iocb.aio_lio_opcode = IOCB_CMD_PWRITE; | 92 | iocb.aio_lio_opcode = IOCB_CMD_PWRITE; |
93 | err = io_submit(ctx, 1, &iocbp); | ||
105 | break; | 94 | break; |
106 | case AIO_MMAP: | 95 | case AIO_MMAP: |
107 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; | 96 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; |
108 | iocb.aio_buf = (unsigned long) &c; | 97 | iocb.aio_buf = (unsigned long) &c; |
109 | iocb.aio_nbytes = sizeof(c); | 98 | iocb.aio_nbytes = sizeof(c); |
99 | err = io_submit(ctx, 1, &iocbp); | ||
110 | break; | 100 | break; |
111 | default: | 101 | default: |
112 | printk("Bogus op in do_aio - %d\n", aio->type); | 102 | printk("Bogus op in do_aio - %d\n", type); |
113 | err = -EINVAL; | 103 | err = -EINVAL; |
114 | goto out; | 104 | break; |
115 | } | 105 | } |
116 | 106 | ||
117 | err = io_submit(ctx, 1, &iocbp); | ||
118 | if(err > 0) | 107 | if(err > 0) |
119 | err = 0; | 108 | err = 0; |
120 | else | 109 | else |
121 | err = -errno; | 110 | err = -errno; |
122 | 111 | ||
123 | out: | ||
124 | return err; | 112 | return err; |
125 | } | 113 | } |
126 | 114 | ||
@@ -129,9 +117,8 @@ static aio_context_t ctx = 0; | |||
129 | static int aio_thread(void *arg) | 117 | static int aio_thread(void *arg) |
130 | { | 118 | { |
131 | struct aio_thread_reply reply; | 119 | struct aio_thread_reply reply; |
132 | struct aio_context *aio; | ||
133 | struct io_event event; | 120 | struct io_event event; |
134 | int err, n; | 121 | int err, n, reply_fd; |
135 | 122 | ||
136 | signal(SIGWINCH, SIG_IGN); | 123 | signal(SIGWINCH, SIG_IGN); |
137 | 124 | ||
@@ -144,22 +131,14 @@ static int aio_thread(void *arg) | |||
144 | "errno = %d\n", errno); | 131 | "errno = %d\n", errno); |
145 | } | 132 | } |
146 | else { | 133 | else { |
147 | /* This is safe as we've just a pointer here. */ | ||
148 | aio = (struct aio_context *) (long) event.data; | ||
149 | if(update_aio(aio, event.res)){ | ||
150 | do_aio(ctx, aio); | ||
151 | continue; | ||
152 | } | ||
153 | |||
154 | reply = ((struct aio_thread_reply) | 134 | reply = ((struct aio_thread_reply) |
155 | { .data = aio, | 135 | { .data = (void *) (long) event.data, |
156 | .err = aio->len }); | 136 | .err = event.res }); |
157 | err = os_write_file(aio->reply_fd, &reply, | 137 | reply_fd = ((struct aio_context *) reply.data)->reply_fd; |
158 | sizeof(reply)); | 138 | err = os_write_file(reply_fd, &reply, sizeof(reply)); |
159 | if(err != sizeof(reply)) | 139 | if(err != sizeof(reply)) |
160 | printk("aio_thread - write failed, " | 140 | printk("aio_thread - write failed, fd = %d, " |
161 | "fd = %d, err = %d\n", aio->reply_fd, | 141 | "err = %d\n", aio_req_fd_r, -err); |
162 | -err); | ||
163 | } | 142 | } |
164 | } | 143 | } |
165 | return 0; | 144 | return 0; |
@@ -167,35 +146,35 @@ static int aio_thread(void *arg) | |||
167 | 146 | ||
168 | #endif | 147 | #endif |
169 | 148 | ||
170 | static int do_not_aio(struct aio_context *aio) | 149 | static int do_not_aio(struct aio_thread_req *req) |
171 | { | 150 | { |
172 | char c; | 151 | char c; |
173 | int err; | 152 | int err; |
174 | 153 | ||
175 | switch(aio->type){ | 154 | switch(req->type){ |
176 | case AIO_READ: | 155 | case AIO_READ: |
177 | err = os_seek_file(aio->fd, aio->offset); | 156 | err = os_seek_file(req->io_fd, req->offset); |
178 | if(err) | 157 | if(err) |
179 | goto out; | 158 | goto out; |
180 | 159 | ||
181 | err = os_read_file(aio->fd, aio->data, aio->len); | 160 | err = os_read_file(req->io_fd, req->buf, req->len); |
182 | break; | 161 | break; |
183 | case AIO_WRITE: | 162 | case AIO_WRITE: |
184 | err = os_seek_file(aio->fd, aio->offset); | 163 | err = os_seek_file(req->io_fd, req->offset); |
185 | if(err) | 164 | if(err) |
186 | goto out; | 165 | goto out; |
187 | 166 | ||
188 | err = os_write_file(aio->fd, aio->data, aio->len); | 167 | err = os_write_file(req->io_fd, req->buf, req->len); |
189 | break; | 168 | break; |
190 | case AIO_MMAP: | 169 | case AIO_MMAP: |
191 | err = os_seek_file(aio->fd, aio->offset); | 170 | err = os_seek_file(req->io_fd, req->offset); |
192 | if(err) | 171 | if(err) |
193 | goto out; | 172 | goto out; |
194 | 173 | ||
195 | err = os_read_file(aio->fd, &c, sizeof(c)); | 174 | err = os_read_file(req->io_fd, &c, sizeof(c)); |
196 | break; | 175 | break; |
197 | default: | 176 | default: |
198 | printk("do_not_aio - bad request type : %d\n", aio->type); | 177 | printk("do_not_aio - bad request type : %d\n", req->type); |
199 | err = -EINVAL; | 178 | err = -EINVAL; |
200 | break; | 179 | break; |
201 | } | 180 | } |
@@ -206,14 +185,14 @@ static int do_not_aio(struct aio_context *aio) | |||
206 | 185 | ||
207 | static int not_aio_thread(void *arg) | 186 | static int not_aio_thread(void *arg) |
208 | { | 187 | { |
209 | struct aio_context *aio; | 188 | struct aio_thread_req req; |
210 | struct aio_thread_reply reply; | 189 | struct aio_thread_reply reply; |
211 | int err; | 190 | int err; |
212 | 191 | ||
213 | signal(SIGWINCH, SIG_IGN); | 192 | signal(SIGWINCH, SIG_IGN); |
214 | while(1){ | 193 | while(1){ |
215 | err = os_read_file(aio_req_fd_r, &aio, sizeof(aio)); | 194 | err = os_read_file(aio_req_fd_r, &req, sizeof(req)); |
216 | if(err != sizeof(aio)){ | 195 | if(err != sizeof(req)){ |
217 | if(err < 0) | 196 | if(err < 0) |
218 | printk("not_aio_thread - read failed, " | 197 | printk("not_aio_thread - read failed, " |
219 | "fd = %d, err = %d\n", aio_req_fd_r, | 198 | "fd = %d, err = %d\n", aio_req_fd_r, |
@@ -224,34 +203,17 @@ static int not_aio_thread(void *arg) | |||
224 | } | 203 | } |
225 | continue; | 204 | continue; |
226 | } | 205 | } |
227 | again: | 206 | err = do_not_aio(&req); |
228 | err = do_not_aio(aio); | 207 | reply = ((struct aio_thread_reply) { .data = req.aio, |
229 | 208 | .err = err }); | |
230 | if(update_aio(aio, err)) | 209 | err = os_write_file(req.aio->reply_fd, &reply, sizeof(reply)); |
231 | goto again; | ||
232 | |||
233 | reply = ((struct aio_thread_reply) { .data = aio, | ||
234 | .err = aio->len }); | ||
235 | err = os_write_file(aio->reply_fd, &reply, sizeof(reply)); | ||
236 | if(err != sizeof(reply)) | 210 | if(err != sizeof(reply)) |
237 | printk("not_aio_thread - write failed, fd = %d, " | 211 | printk("not_aio_thread - write failed, fd = %d, " |
238 | "err = %d\n", aio_req_fd_r, -err); | 212 | "err = %d\n", aio_req_fd_r, -err); |
239 | } | 213 | } |
240 | } | 214 | } |
241 | 215 | ||
242 | static int submit_aio_24(struct aio_context *aio) | ||
243 | { | ||
244 | int err; | ||
245 | |||
246 | err = os_write_file(aio_req_fd_w, &aio, sizeof(aio)); | ||
247 | if(err == sizeof(aio)) | ||
248 | err = 0; | ||
249 | |||
250 | return err; | ||
251 | } | ||
252 | |||
253 | static int aio_pid = -1; | 216 | static int aio_pid = -1; |
254 | static int (*submit_proc)(struct aio_context *aio); | ||
255 | 217 | ||
256 | static int init_aio_24(void) | 218 | static int init_aio_24(void) |
257 | { | 219 | { |
@@ -283,33 +245,11 @@ static int init_aio_24(void) | |||
283 | #endif | 245 | #endif |
284 | printk("2.6 host AIO support not used - falling back to I/O " | 246 | printk("2.6 host AIO support not used - falling back to I/O " |
285 | "thread\n"); | 247 | "thread\n"); |
286 | |||
287 | submit_proc = submit_aio_24; | ||
288 | |||
289 | return 0; | 248 | return 0; |
290 | } | 249 | } |
291 | 250 | ||
292 | #ifdef HAVE_AIO_ABI | 251 | #ifdef HAVE_AIO_ABI |
293 | #define DEFAULT_24_AIO 0 | 252 | #define DEFAULT_24_AIO 0 |
294 | static int submit_aio_26(struct aio_context *aio) | ||
295 | { | ||
296 | struct aio_thread_reply reply; | ||
297 | int err; | ||
298 | |||
299 | err = do_aio(ctx, aio); | ||
300 | if(err){ | ||
301 | reply = ((struct aio_thread_reply) { .data = aio, | ||
302 | .err = err }); | ||
303 | err = os_write_file(aio->reply_fd, &reply, sizeof(reply)); | ||
304 | if(err != sizeof(reply)) | ||
305 | printk("submit_aio_26 - write failed, " | ||
306 | "fd = %d, err = %d\n", aio->reply_fd, -err); | ||
307 | else err = 0; | ||
308 | } | ||
309 | |||
310 | return err; | ||
311 | } | ||
312 | |||
313 | static int init_aio_26(void) | 253 | static int init_aio_26(void) |
314 | { | 254 | { |
315 | unsigned long stack; | 255 | unsigned long stack; |
@@ -330,22 +270,39 @@ static int init_aio_26(void) | |||
330 | aio_pid = err; | 270 | aio_pid = err; |
331 | 271 | ||
332 | printk("Using 2.6 host AIO\n"); | 272 | printk("Using 2.6 host AIO\n"); |
273 | return 0; | ||
274 | } | ||
275 | |||
276 | static int submit_aio_26(enum aio_type type, int io_fd, char *buf, int len, | ||
277 | unsigned long long offset, struct aio_context *aio) | ||
278 | { | ||
279 | struct aio_thread_reply reply; | ||
280 | int err; | ||
333 | 281 | ||
334 | submit_proc = submit_aio_26; | 282 | err = do_aio(ctx, type, io_fd, buf, len, offset, aio); |
283 | if(err){ | ||
284 | reply = ((struct aio_thread_reply) { .data = aio, | ||
285 | .err = err }); | ||
286 | err = os_write_file(aio->reply_fd, &reply, sizeof(reply)); | ||
287 | if(err != sizeof(reply)) | ||
288 | printk("submit_aio_26 - write failed, " | ||
289 | "fd = %d, err = %d\n", aio->reply_fd, -err); | ||
290 | else err = 0; | ||
291 | } | ||
335 | 292 | ||
336 | return 0; | 293 | return err; |
337 | } | 294 | } |
338 | 295 | ||
339 | #else | 296 | #else |
340 | #define DEFAULT_24_AIO 1 | 297 | #define DEFAULT_24_AIO 1 |
341 | static int submit_aio_26(struct aio_context *aio) | 298 | static int init_aio_26(void) |
342 | { | 299 | { |
343 | return -ENOSYS; | 300 | return -ENOSYS; |
344 | } | 301 | } |
345 | 302 | ||
346 | static int init_aio_26(void) | 303 | static int submit_aio_26(enum aio_type type, int io_fd, char *buf, int len, |
304 | unsigned long long offset, struct aio_context *aio) | ||
347 | { | 305 | { |
348 | submit_proc = submit_aio_26; | ||
349 | return -ENOSYS; | 306 | return -ENOSYS; |
350 | } | 307 | } |
351 | #endif | 308 | #endif |
@@ -412,7 +369,33 @@ static void exit_aio(void) | |||
412 | 369 | ||
413 | __uml_exitcall(exit_aio); | 370 | __uml_exitcall(exit_aio); |
414 | 371 | ||
415 | int submit_aio(struct aio_context *aio) | 372 | static int submit_aio_24(enum aio_type type, int io_fd, char *buf, int len, |
373 | unsigned long long offset, struct aio_context *aio) | ||
416 | { | 374 | { |
417 | return (*submit_proc)(aio); | 375 | struct aio_thread_req req = { .type = type, |
376 | .io_fd = io_fd, | ||
377 | .offset = offset, | ||
378 | .buf = buf, | ||
379 | .len = len, | ||
380 | .aio = aio, | ||
381 | }; | ||
382 | int err; | ||
383 | |||
384 | err = os_write_file(aio_req_fd_w, &req, sizeof(req)); | ||
385 | if(err == sizeof(req)) | ||
386 | err = 0; | ||
387 | |||
388 | return err; | ||
389 | } | ||
390 | |||
391 | int submit_aio(enum aio_type type, int io_fd, char *buf, int len, | ||
392 | unsigned long long offset, int reply_fd, | ||
393 | struct aio_context *aio) | ||
394 | { | ||
395 | aio->reply_fd = reply_fd; | ||
396 | if(aio_24) | ||
397 | return submit_aio_24(type, io_fd, buf, len, offset, aio); | ||
398 | else { | ||
399 | return submit_aio_26(type, io_fd, buf, len, offset, aio); | ||
400 | } | ||
418 | } | 401 | } |