11 #include <asm/unistd.h>
26 #if defined(HAVE_AIO_ABI)
34 #if !defined(HAVE_AIO_LIBC)
69 struct iocb *iocbp = & ((
struct iocb) {
70 .aio_data = (
unsigned long) aio,
95 return (io_submit(ctx, 1, &iocbp) > 0) ? 0 : -
errno;
101 static int aio_thread(
void *
arg)
105 int err,
n, reply_fd;
110 n = io_getevents(ctx, 1, 1, &
event,
NULL);
115 "errno = %d\n", errno);
119 { .data = (
void *) (
long)
event.data,
121 reply_fd = ((
struct aio_context *) reply.data)->reply_fd;
122 err =
write(reply_fd, &reply,
sizeof(reply));
123 if (err !=
sizeof(reply))
125 "fd = %d, err = %d\n", reply_fd, errno);
136 unsigned long long actual;
140 if (actual != req->
offset)
165 static int aio_req_fd_r = -1;
166 static int aio_req_fd_w = -1;
167 static int aio_pid = -1;
168 static unsigned long aio_stack;
170 static int not_aio_thread(
void *arg)
178 err =
read(aio_req_fd_r, &req,
sizeof(req));
179 if (err !=
sizeof(req)) {
182 "read failed, fd = %d, err = %d\n",
187 "read, fd = %d, length = %d\n",
192 err = do_not_aio(&req);
195 err =
write(req.
aio->reply_fd, &reply,
sizeof(reply));
196 if (err !=
sizeof(reply))
198 "fd = %d, err = %d\n", req.
aio->reply_fd, errno);
204 static int init_aio_24(
void)
212 aio_req_fd_w = fds[0];
213 aio_req_fd_r = fds[1];
243 #define DEFAULT_24_AIO 0
244 static int init_aio_26(
void)
248 if (io_setup(256, &ctx)) {
251 "err = %d\n", errno);
266 static int submit_aio_26(
enum aio_type type,
int io_fd,
char *buf,
int len,
267 unsigned long long offset,
struct aio_context *aio)
272 err = do_aio(ctx, type, io_fd, buf, len, offset, aio);
277 if (err !=
sizeof(reply)) {
280 "fd = %d, err = %d\n", aio->
reply_fd, -err);
289 #define DEFAULT_24_AIO 1
290 static int init_aio_26(
void)
295 static int submit_aio_26(
enum aio_type type,
int io_fd,
char *buf,
int len,
296 unsigned long long offset,
struct aio_context *aio)
313 " This is used to force UML to use 2.4-style AIO even when 2.6 AIO is\n"
314 " available. 2.4 AIO is a single thread that handles one request at a\n"
315 " time, synchronously. 2.6 AIO is a thread which uses the 2.6 AIO \n"
316 " interface to handle an arbitrary number of pending requests. 2.6 AIO \n"
317 " is not available in tt mode, on 2.4 hosts, or when UML is built with\n"
318 " /usr/include/linux/aio_abi.h not available. Many distributions don't\n"
319 " include aio_abi.h, so you will need to copy it from a kernel tree to\n"
320 " your /usr/include/linux in order to build an AIO-capable UML\n\n"
323 static int init_aio(
void)
329 if (err && (errno ==
ENOSYS)) {
331 "host - reverting to 2.4 AIO\n");
338 return init_aio_24();
362 static int submit_aio_24(
enum aio_type type,
int io_fd,
char *buf,
int len,
363 unsigned long long offset,
struct aio_context *aio)
374 err =
write(aio_req_fd_w, &req,
sizeof(req));
375 if (err ==
sizeof(req))
383 unsigned long long offset,
int reply_fd,
388 return submit_aio_24(type, io_fd, buf, len, offset, aio);
390 return submit_aio_26(type, io_fd, buf, len, offset, aio);