src/server/daemon/vfs.c

branch
aio
changeset 172
5580517faafc
parent 165
6942a8c3e737
child 185
b4d7ccf4e06d
--- a/src/server/daemon/vfs.c	Sat Feb 04 16:42:11 2017 +0100
+++ b/src/server/daemon/vfs.c	Sat Feb 18 13:27:25 2017 +0100
@@ -32,12 +32,14 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <aio.h>
 
 #include <ucx/map.h>
 
 #include "../util/pool.h"
 #include "acl.h"
 #include "vfs.h"
+#include "event.h"
 
 #define VFS_MALLOC(pool, size) pool ? pool_malloc(pool, size) : malloc(size)
 #define VFS_FREE(pool, ptr) pool ? pool_free(pool, ptr) : free(ptr)
@@ -58,7 +60,9 @@
     sys_file_read,
     sys_file_write,
     sys_file_seek,
-    sys_file_close
+    sys_file_close,
+    sys_file_aioread,
+    sys_file_aiowrite
 };
 
 static VFS_DIRIO sys_dir_io = {
@@ -497,6 +501,19 @@
     close(fd->fd);
 }
 
+int sys_file_aioread(aiocb_s *aiocb) {
+    WS_ASSERT(aiocb->buf);
+    WS_ASSERT(aiocb->nbytes > 0);
+    return ev_aioread(aiocb->filedes->fd, aiocb);
+}
+
+int sys_file_aiowrite(aiocb_s *aiocb) {
+    WS_ASSERT(aiocb->buf);
+    WS_ASSERT(aiocb->nbytes > 0);
+    return ev_aiowrite(aiocb->filedes->fd, aiocb);
+}
+
+
 int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) {
     SysVFSDir *dirdata = dir->data;
     struct dirent *result = NULL;
@@ -578,3 +595,35 @@
     vfs_close(fd);
     return 0;
 }
+
+// AIO API
+
+NSAPI_PUBLIC int system_aio_read(aiocb_s *aiocb) {
+    if(!aiocb->event || !aiocb->evhandler) {
+        return -1;
+    }
+   
+    SYS_FILE file = aiocb->filedes;
+    aiocb->event->object = (intptr_t)aiocb;
+    if(file->io->opt_aioread) {
+        return file->io->opt_aioread(aiocb);
+    } else {
+        // TODO: implement
+        return -1;
+    }
+}
+
+NSAPI_PUBLIC int system_aio_write(aiocb_s *aiocb) {
+    if(!aiocb->event || !aiocb->evhandler) {
+        return -1;
+    }
+    
+    SYS_FILE file = aiocb->filedes;
+    aiocb->event->object = (intptr_t)aiocb;
+    if(file->io->opt_aiowrite) {
+        return file->io->opt_aiowrite(aiocb);
+    } else {
+        // TODO: implement
+        return -1;
+    }
+}

mercurial