Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[cascardo/linux.git] / arch / um / os-Linux / aio.c
index f897140..9bf944f 100644 (file)
@@ -24,9 +24,6 @@ struct aio_thread_req {
        struct aio_context *aio;
 };
 
-static int aio_req_fd_r = -1;
-static int aio_req_fd_w = -1;
-
 #if defined(HAVE_AIO_ABI)
 #include <linux/aio_abi.h>
 
@@ -111,6 +108,7 @@ static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf,
        return err;
 }
 
+/* Initialized in an initcall and unchanged thereafter */
 static aio_context_t ctx = 0;
 
 static int aio_thread(void *arg)
@@ -134,10 +132,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", aio_req_fd_r, -err);
+                                      "err = %d\n", reply_fd, errno);
                }
        }
        return 0;
@@ -148,40 +146,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 int not_aio_thread(void *arg)
 {
        struct aio_thread_req req;
@@ -190,12 +186,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);
@@ -204,18 +200,16 @@ 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", aio_req_fd_r, -err);
+                              "err = %d\n", req.aio->reply_fd, errno);
        }
 
        return 0;
 }
 
-static int aio_pid = -1;
-
 static int init_aio_24(void)
 {
        unsigned long stack;
@@ -227,6 +221,11 @@ 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);
        if(err < 0)
@@ -284,10 +283,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;
        }
 
@@ -308,6 +309,7 @@ static int submit_aio_26(enum aio_type type, int io_fd, char *buf, int len,
 }
 #endif
 
+/* Initialized in an initcall and unchanged thereafter */
 static int aio_24 = DEFAULT_24_AIO;
 
 static int __init set_aio_24(char *name, int *add)
@@ -381,9 +383,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;
 }