adds platform independent aio functions aio

Wed, 10 Jan 2018 18:47:37 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 10 Jan 2018 18:47:37 +0100
branch
aio
changeset 187
4384bfbb7e26
parent 186
8041ac363f26
child 188
0e6a05c779e0

adds platform independent aio functions

src/server/daemon/event_bsd.c file | annotate | diff | comparison | revisions
src/server/daemon/event_linux.c file | annotate | diff | comparison | revisions
src/server/daemon/event_solaris.c file | annotate | diff | comparison | revisions
src/server/daemon/threadpools.c file | annotate | diff | comparison | revisions
src/server/daemon/vfs.c file | annotate | diff | comparison | revisions
src/server/daemon/vfs.h file | annotate | diff | comparison | revisions
src/server/public/nsapi.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/event_bsd.c	Wed Jan 10 17:25:55 2018 +0100
+++ b/src/server/daemon/event_bsd.c	Wed Jan 10 18:47:37 2018 +0100
@@ -122,6 +122,6 @@
     return kevent(h->kqueue, &kev, 1, NULL, 0, NULL);
 }
 
-int evt_send(EventHandler *h, Event *event) {
+int event_send(EventHandler *h, Event *event) {
     return 0;
 }
--- a/src/server/daemon/event_linux.c	Wed Jan 10 17:25:55 2018 +0100
+++ b/src/server/daemon/event_linux.c	Wed Jan 10 18:47:37 2018 +0100
@@ -177,7 +177,7 @@
     return epoll_ctl(h->ep, EPOLL_CTL_DEL, fd, NULL);
 }
 
-int evt_send(EventHandler *h, Event *event) {
+int event_send(EventHandler *h, Event *event) {
     event->object = 0;
     event->events = 0;
     ssize_t r = write(h->eventfd, &event, sizeof(Event*));
@@ -191,7 +191,7 @@
     if(result < 0) {
         cb->result_errno = errno;
     }
-    return evt_send(cb->evhandler, cb->event);
+    return event_send(cb->evhandler, cb->event);
 }
 
 int ev_aiowrite(int fd, aiocb_s *cb) {
@@ -200,7 +200,7 @@
     if(result < 0) {
         cb->result_errno = errno;
     }
-    return evt_send(cb->evhandler, cb->event);
+    return event_send(cb->evhandler, cb->event);
 }
 
 
--- a/src/server/daemon/event_solaris.c	Wed Jan 10 17:25:55 2018 +0100
+++ b/src/server/daemon/event_solaris.c	Wed Jan 10 18:47:37 2018 +0100
@@ -156,7 +156,7 @@
     return port_dissociate(h->port, PORT_SOURCE_FD, (uintptr_t)fd);
 }
 
-int ev_send(EventHandler *h, Event *event) {
+int event_send(EventHandler *h, Event *event) {
     event->object = 0;
     event->events = 0;
     return port_send(h->port, 0, event);
--- a/src/server/daemon/threadpools.c	Wed Jan 10 17:25:55 2018 +0100
+++ b/src/server/daemon/threadpools.c	Wed Jan 10 18:47:37 2018 +0100
@@ -34,8 +34,8 @@
 #include "threadpools.h"
 
 
-UcxMap *thread_pool_map = NULL;
-int numthrpools = 0;
+static UcxMap *thread_pool_map = NULL;
+static int numthrpools = 0;
 
 threadpool_t *default_thread_pool = NULL;
 
--- a/src/server/daemon/vfs.c	Wed Jan 10 17:25:55 2018 +0100
+++ b/src/server/daemon/vfs.c	Wed Jan 10 18:47:37 2018 +0100
@@ -39,6 +39,7 @@
 #include "../util/pool.h"
 #include "acl.h"
 #include "vfs.h"
+#include "threadpools.h"
 #include "event.h"
 
 #define VFS_MALLOC(pool, size) pool ? pool_malloc(pool, size) : malloc(size)
@@ -61,8 +62,10 @@
     sys_file_write,
     sys_file_seek,
     sys_file_close,
-    sys_file_aioread,
-    sys_file_aiowrite
+    //sys_file_aioread,
+    //sys_file_aiowrite,
+    NULL,
+    NULL
 };
 
 static VFS_DIRIO sys_dir_io = {
@@ -602,8 +605,8 @@
     if(file->io->opt_aioread) {
         return file->io->opt_aioread(aiocb);
     } else {
-        // TODO: implement
-        return -1;
+        vfs_queue_aio(aiocb, VFS_AIO_READ);
+        return 0;
     }
 }
 
@@ -617,7 +620,38 @@
     if(file->io->opt_aiowrite) {
         return file->io->opt_aiowrite(aiocb);
     } else {
-        // TODO: implement
-        return -1;
+        vfs_queue_aio(aiocb, VFS_AIO_WRITE);
+        return 0;
     }
 }
+
+static void* vfs_aio_read(aiocb_s *aiocb) {
+    system_lseek(aiocb->filedes, aiocb->offset, SEEK_SET);
+    int result = system_fread(aiocb->filedes, aiocb->buf, aiocb->nbytes);
+    aiocb->result = result;
+    if(result < 0) {
+        aiocb->result_errno = errno;
+    }
+    event_send(aiocb->evhandler, aiocb->event);
+    return NULL;
+}
+
+static void* vfs_aio_write(aiocb_s *aiocb) {
+    system_lseek(aiocb->filedes, aiocb->offset, SEEK_SET);
+    int result = system_fwrite(aiocb->filedes, aiocb->buf, aiocb->nbytes);
+    aiocb->result = result;
+    if(result < 0) {
+        aiocb->result_errno = errno;
+    }
+    event_send(aiocb->evhandler, aiocb->event);
+    return NULL;
+}
+
+void vfs_queue_aio(aiocb_s *aiocb, VFSAioOp op) {
+    threadpool_t *pool = get_default_threadpool(); // TODO: use IOPool
+    if(op == VFS_AIO_READ) {
+        threadpool_run(pool, (job_callback_f)vfs_aio_read, aiocb);
+    } else if(VFS_AIO_WRITE) {
+        threadpool_run(pool, (job_callback_f)vfs_aio_write, aiocb);
+    }
+}
--- a/src/server/daemon/vfs.h	Wed Jan 10 17:25:55 2018 +0100
+++ b/src/server/daemon/vfs.h	Wed Jan 10 18:47:37 2018 +0100
@@ -40,6 +40,12 @@
     DIR           *dir;
     struct dirent *cur;
 } SysVFSDir;
+
+enum VFSAioOp {
+    VFS_AIO_READ = 0,
+    VFS_AIO_WRITE
+};
+typedef enum VFSAioOp VFSAioOp;
     
 int vfs_init();
 
@@ -71,6 +77,8 @@
 int sys_mkdir(VFSContext *ctx, char *path, SysACL *sysacl);
 int sys_unlink(VFSContext *ctx, char *path, SysACL *sysacl);
 
+void vfs_queue_aio(aiocb_s *aiocb, VFSAioOp op);
+
 #ifdef	__cplusplus
 }
 #endif
--- a/src/server/public/nsapi.h	Wed Jan 10 17:25:55 2018 +0100
+++ b/src/server/public/nsapi.h	Wed Jan 10 18:47:37 2018 +0100
@@ -1570,6 +1570,7 @@
 int event_pollin(EventHandler *ev, SYS_NETFD fd, Event *event);
 int event_pollout(EventHandler *ev, SYS_NETFD fd, Event *event);
 int event_removepoll(EventHandler *ev, SYS_NETFD fd);
+int event_send(EventHandler *ev, Event *event);
 
 // assert
 void ws_log_assert(const char *file, const char *func, int line);

mercurial