]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/um/os-Linux/aio.c
Merge branch 'linux-2.6' into for-2.6.24
[linux-2.6-omap-h63xx.git] / arch / um / os-Linux / aio.c
index 6ff12743a0bdbe3e396e78b19ac667b52265c74b..59348359f9ab3bd0bdf9b469ce850937e0052c36 100644 (file)
@@ -14,6 +14,7 @@
 #include "init.h"
 #include "user.h"
 #include "mode.h"
+#include "kern_constants.h"
 
 struct aio_thread_req {
        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,
                  int len, unsigned long long offset, struct aio_context *aio)
 {
-       struct iocb iocb, *iocbp = &iocb;
+       struct iocb *iocbp = & ((struct iocb) {
+                                   .aio_data       = (unsigned long) aio,
+                                   .aio_fildes     = fd,
+                                   .aio_buf        = (unsigned long) buf,
+                                   .aio_nbytes     = len,
+                                   .aio_offset     = offset
+                            });
        char c;
-       int err;
 
-       iocb = ((struct iocb) { .aio_data       = (unsigned long) aio,
-                               .aio_reqprio    = 0,
-                               .aio_fildes     = fd,
-                               .aio_buf        = (unsigned long) buf,
-                               .aio_nbytes     = len,
-                               .aio_offset     = offset,
-                               .aio_reserved1  = 0,
-                               .aio_reserved2  = 0,
-                               .aio_reserved3  = 0 });
-
-       switch(type){
+       switch (type) {
        case AIO_READ:
-               iocb.aio_lio_opcode = IOCB_CMD_PREAD;
-               err = io_submit(ctx, 1, &iocbp);
+               iocbp->aio_lio_opcode = IOCB_CMD_PREAD;
                break;
        case AIO_WRITE:
-               iocb.aio_lio_opcode = IOCB_CMD_PWRITE;
-               err = io_submit(ctx, 1, &iocbp);
+               iocbp->aio_lio_opcode = IOCB_CMD_PWRITE;
                break;
        case AIO_MMAP:
-               iocb.aio_lio_opcode = IOCB_CMD_PREAD;
-               iocb.aio_buf = (unsigned long) &c;
-               iocb.aio_nbytes = sizeof(c);
-               err = io_submit(ctx, 1, &iocbp);
+               iocbp->aio_lio_opcode = IOCB_CMD_PREAD;
+               iocbp->aio_buf = (unsigned long) &c;
+               iocbp->aio_nbytes = sizeof(c);
                break;
        default:
-               printk("Bogus op in do_aio - %d\n", type);
-               err = -EINVAL;
-               break;
+               printk(UM_KERN_ERR "Bogus op in do_aio - %d\n", type);
+               return -EINVAL;
        }
 
-       if(err > 0)
-               err = 0;
-       else
-               err = -errno;
-
-       return err;
+       return (io_submit(ctx, 1, &iocbp) > 0) ? 0 : -errno;
 }
 
 /* Initialized in an initcall and unchanged thereafter */
@@ -132,10 +119,10 @@ static int aio_thread(void *arg)
                                { .data = (void *) (long) event.data,
                                                .err    = event.res });
                        reply_fd = ((struct aio_context *) reply.data)->reply_fd;
-                       err = os_write_file(reply_fd, &reply, sizeof(reply));
+                       err = write(reply_fd, &reply, sizeof(reply));
                        if(err != sizeof(reply))
                                printk("aio_thread - write failed, fd = %d, "
-                                      "err = %d\n", reply_fd, -err);
+                                      "err = %d\n", reply_fd, errno);
                }
        }
        return 0;
@@ -146,44 +133,38 @@ static int aio_thread(void *arg)
 static int do_not_aio(struct aio_thread_req *req)
 {
        char c;
-       int err;
+       unsigned long long actual;
+       int n;
+
+       actual = lseek64(req->io_fd, req->offset, SEEK_SET);
+       if(actual != req->offset)
+               return -errno;
 
        switch(req->type){
        case AIO_READ:
-               err = os_seek_file(req->io_fd, req->offset);
-               if(err)
-                       goto out;
-
-               err = os_read_file(req->io_fd, req->buf, req->len);
+               n = read(req->io_fd, req->buf, req->len);
                break;
        case AIO_WRITE:
-               err = os_seek_file(req->io_fd, req->offset);
-               if(err)
-                       goto out;
-
-               err = os_write_file(req->io_fd, req->buf, req->len);
+               n = write(req->io_fd, req->buf, req->len);
                break;
        case AIO_MMAP:
-               err = os_seek_file(req->io_fd, req->offset);
-               if(err)
-                       goto out;
-
-               err = os_read_file(req->io_fd, &c, sizeof(c));
+               n = read(req->io_fd, &c, sizeof(c));
                break;
        default:
                printk("do_not_aio - bad request type : %d\n", req->type);
-               err = -EINVAL;
-               break;
+               return -EINVAL;
        }
 
-out:
-       return err;
+       if(n < 0)
+               return -errno;
+       return 0;
 }
 
 /* These are initialized in initcalls and not changed */
 static int aio_req_fd_r = -1;
 static int aio_req_fd_w = -1;
 static int aio_pid = -1;
+static unsigned long aio_stack;
 
 static int not_aio_thread(void *arg)
 {
@@ -193,12 +174,12 @@ static int not_aio_thread(void *arg)
 
        signal(SIGWINCH, SIG_IGN);
        while(1){
-               err = os_read_file(aio_req_fd_r, &req, sizeof(req));
+               err = read(aio_req_fd_r, &req, sizeof(req));
                if(err != sizeof(req)){
                        if(err < 0)
                                printk("not_aio_thread - read failed, "
                                       "fd = %d, err = %d\n", aio_req_fd_r,
-                                      -err);
+                                      errno);
                        else {
                                printk("not_aio_thread - short read, fd = %d, "
                                       "length = %d\n", aio_req_fd_r, err);
@@ -207,11 +188,11 @@ static int not_aio_thread(void *arg)
                }
                err = do_not_aio(&req);
                reply = ((struct aio_thread_reply) { .data      = req.aio,
-                                        .err   = err });
-               err = os_write_file(req.aio->reply_fd, &reply, sizeof(reply));
+                                                    .err       = err });
+               err = write(req.aio->reply_fd, &reply, sizeof(reply));
                if(err != sizeof(reply))
                        printk("not_aio_thread - write failed, fd = %d, "
-                              "err = %d\n", req.aio->reply_fd, -err);
+                              "err = %d\n", req.aio->reply_fd, errno);
        }
 
        return 0;
@@ -219,7 +200,6 @@ static int not_aio_thread(void *arg)
 
 static int init_aio_24(void)
 {
-       unsigned long stack;
        int fds[2], err;
 
        err = os_pipe(fds, 1, 1);
@@ -228,8 +208,13 @@ static int init_aio_24(void)
 
        aio_req_fd_w = fds[0];
        aio_req_fd_r = fds[1];
+
+       err = os_set_fd_block(aio_req_fd_w, 0);
+       if(err)
+               goto out_close_pipe;
+
        err = run_helper_thread(not_aio_thread, NULL,
-                               CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0);
+                               CLONE_FILES | CLONE_VM | SIGCHLD, &aio_stack);
        if(err < 0)
                goto out_close_pipe;
 
@@ -254,7 +239,6 @@ out:
 #define DEFAULT_24_AIO 0
 static int init_aio_26(void)
 {
-       unsigned long stack;
        int err;
 
        if(io_setup(256, &ctx)){
@@ -265,7 +249,7 @@ static int init_aio_26(void)
        }
 
        err = run_helper_thread(aio_thread, NULL,
-                               CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0);
+                               CLONE_FILES | CLONE_VM | SIGCHLD, &aio_stack);
        if(err < 0)
                return err;
 
@@ -285,10 +269,12 @@ static int submit_aio_26(enum aio_type type, int io_fd, char *buf, int len,
        if(err){
                reply = ((struct aio_thread_reply) { .data = aio,
                                         .err  = err });
-               err = os_write_file(aio->reply_fd, &reply, sizeof(reply));
-               if(err != sizeof(reply))
+               err = write(aio->reply_fd, &reply, sizeof(reply));
+               if(err != sizeof(reply)){
+                       err = -errno;
                        printk("submit_aio_26 - write failed, "
                               "fd = %d, err = %d\n", aio->reply_fd, -err);
+               }
                else err = 0;
        }
 
@@ -365,8 +351,10 @@ __initcall(init_aio);
 
 static void exit_aio(void)
 {
-       if(aio_pid != -1)
+       if (aio_pid != -1) {
                os_kill_process(aio_pid, 1);
+               free_stack(aio_stack, 0);
+       }
 }
 
 __uml_exitcall(exit_aio);
@@ -383,9 +371,10 @@ static int submit_aio_24(enum aio_type type, int io_fd, char *buf, int len,
        };
        int err;
 
-       err = os_write_file(aio_req_fd_w, &req, sizeof(req));
+       err = write(aio_req_fd_w, &req, sizeof(req));
        if(err == sizeof(req))
                err = 0;
+       else err = -errno;
 
        return err;
 }