summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kernel/handle.c2
-rw-r--r--src/kernel/proc.c4
-rw-r--r--src/kernel/syscalls.c8
-rw-r--r--src/kernel/vfs/request.c93
-rw-r--r--src/kernel/vfs/request.h7
-rw-r--r--src/kernel/vfs/root.c4
6 files changed, 49 insertions, 69 deletions
diff --git a/src/kernel/handle.c b/src/kernel/handle.c
index f5255c0..103c788 100644
--- a/src/kernel/handle.c
+++ b/src/kernel/handle.c
@@ -18,7 +18,7 @@ void handle_close(struct handle *h) {
switch (h->type) {
case HANDLE_FILE:
- vfs_request_create((struct vfs_request) {
+ vfsreq_create((struct vfs_request) {
.type = VFSOP_CLOSE,
.id = h->file.id,
.caller = NULL,
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 76f3093..ebe291a 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -241,7 +241,7 @@ void process_kill(struct process *p, int ret) {
if (p->state == PS_DEAD || p->state == PS_DEADER) return;
if (p->handled_req) {
- vfs_request_cancel(p->handled_req, ret);
+ vfsreq_finish(p->handled_req, -1);
p->handled_req = NULL;
}
if (p->controlled) {
@@ -252,7 +252,7 @@ void process_kill(struct process *p, int ret) {
struct vfs_request *q = p->controlled->queue;
while (q) {
struct vfs_request *q2 = q->queue_next;
- vfs_request_cancel(q, ret);
+ vfsreq_finish(q, -1);
q = q2;
}
p->controlled->queue = NULL;
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index ca717ae..1e33632 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -66,7 +66,7 @@ handle_t _syscall_open(const char __user *path, int len) {
memcpy(path_buf, path_buf + mount->prefix_len, len);
}
- return vfs_request_create((struct vfs_request) {
+ return vfsreq_create((struct vfs_request) {
.type = VFSOP_OPEN,
.input = {
.kern = true,
@@ -132,7 +132,7 @@ fail:
int _syscall_read(handle_t handle_num, void __user *buf, size_t len, int offset) {
struct handle *handle = process_handle_get(process_current, handle_num, HANDLE_FILE);
if (!handle) return -1;
- return vfs_request_create((struct vfs_request) {
+ return vfsreq_create((struct vfs_request) {
.type = VFSOP_READ,
.output = {
.buf = (userptr_t) buf,
@@ -148,7 +148,7 @@ int _syscall_read(handle_t handle_num, void __user *buf, size_t len, int offset)
int _syscall_write(handle_t handle_num, const void __user *buf, size_t len, int offset) {
struct handle *handle = process_handle_get(process_current, handle_num, HANDLE_FILE);
if (!handle) return -1;
- return vfs_request_create((struct vfs_request) {
+ return vfsreq_create((struct vfs_request) {
.type = VFSOP_WRITE,
.input = {
.buf = (userptr_t) buf,
@@ -226,7 +226,7 @@ int _syscall_fs_respond(char __user *buf, int ret) {
}
process_current->handled_req = NULL;
- vfs_request_finish(req, ret);
+ vfsreq_finish(req, ret);
return 0;
}
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index 7c1861d..fb196ee 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -6,10 +6,10 @@
#include <kernel/vfs/root.h>
#include <shared/mem.h>
-int vfs_request_create(struct vfs_request req_) {
+int vfsreq_create(struct vfs_request req_) {
struct vfs_request *req = kmalloc(sizeof *req);
memcpy(req, &req_, sizeof *req);
- /* freed in vfs_request_finish or vfs_request_cancel */
+ /* freed in vfsreq_finish */
if (req->backend)
req->backend->refcount++;
@@ -20,7 +20,7 @@ int vfs_request_create(struct vfs_request req_) {
}
if (!req->backend || !req->backend->potential_handlers)
- return vfs_request_finish(req, -1);
+ return vfsreq_finish(req, -1);
switch (req->backend->type) {
case VFS_BACK_ROOT:
@@ -39,46 +39,7 @@ int vfs_request_create(struct vfs_request req_) {
}
}
-int vfs_backend_accept(struct vfs_backend *backend) {
- struct vfs_request *req = backend->queue;
- struct process *handler = backend->handler;
- struct fs_wait_response res = {0};
- int len = 0;
-
- if (!handler) return -1;
- assert(handler->state == PS_WAITS4REQUEST);
- assert(!handler->handled_req);
-
- if (!req) return -1;
- backend->queue = req->queue_next;
-
- if (req->input.buf) {
- len = min(req->input.len, handler->awaited_req.max_len);
- if (!virt_cpy(handler->pages, handler->awaited_req.buf,
- req->input.kern ? NULL : req->caller->pages, req->input.buf, len))
- goto fail; // can't copy buffer
- }
-
- res.len = len;
- res.capacity = req->output.len;
- res.id = req->id;
- res.offset = req->offset;
- res.op = req->type;
-
- if (!virt_cpy_to(handler->pages,
- handler->awaited_req.res, &res, sizeof res))
- goto fail; // can't copy response struct
-
- process_transition(handler, PS_RUNNING);
- handler->handled_req = req;
- req->backend->handler = NULL;
- regs_savereturn(&handler->regs, 0);
- return 0;
-fail:
- panic_unimplemented(); // TODO
-}
-
-int vfs_request_finish(struct vfs_request *req, int ret) {
+int vfsreq_finish(struct vfs_request *req, int ret) {
if (req->type == VFSOP_OPEN && ret >= 0) {
// open() calls need special handling
// we need to wrap the id returned by the VFS in a handle passed to
@@ -115,23 +76,43 @@ int vfs_request_finish(struct vfs_request *req, int ret) {
return ret;
}
-void vfs_request_cancel(struct vfs_request *req, int ret) {
- // TODO merge with vfs_request_finish
- if (req->caller) {
- assert(req->caller->state == PS_WAITS4FS);
+int vfs_backend_accept(struct vfs_backend *backend) {
+ struct vfs_request *req = backend->queue;
+ struct process *handler = backend->handler;
+ struct fs_wait_response res = {0};
+ int len = 0;
- if (req->input.kern)
- kfree(req->input.buf_kern);
+ if (!handler) return -1;
+ assert(handler->state == PS_WAITS4REQUEST);
+ assert(!handler->handled_req);
- // ret must always be negative, so it won't be confused with a success
- if (ret > 0) ret = -ret;
- if (ret == 0) ret = -1;
- regs_savereturn(&req->caller->regs, ret);
- process_transition(req->caller, PS_RUNNING);
+ if (!req) return -1;
+ backend->queue = req->queue_next;
+
+ if (req->input.buf) {
+ len = min(req->input.len, handler->awaited_req.max_len);
+ if (!virt_cpy(handler->pages, handler->awaited_req.buf,
+ req->input.kern ? NULL : req->caller->pages, req->input.buf, len))
+ goto fail; // can't copy buffer
}
- vfs_backend_refdown(req->backend);
- kfree(req);
+ res.len = len;
+ res.capacity = req->output.len;
+ res.id = req->id;
+ res.offset = req->offset;
+ res.op = req->type;
+
+ if (!virt_cpy_to(handler->pages,
+ handler->awaited_req.res, &res, sizeof res))
+ goto fail; // can't copy response struct
+
+ process_transition(handler, PS_RUNNING);
+ handler->handled_req = req;
+ req->backend->handler = NULL;
+ regs_savereturn(&handler->regs, 0);
+ return 0;
+fail:
+ panic_unimplemented(); // TODO
}
void vfs_backend_refdown(struct vfs_backend *b) {
diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h
index 69dad07..af1310b 100644
--- a/src/kernel/vfs/request.h
+++ b/src/kernel/vfs/request.h
@@ -54,11 +54,10 @@ struct vfs_request {
};
/** Assigns the vfs_request to the caller, and dispatches the call */
-int vfs_request_create(struct vfs_request);
+int vfsreq_create(struct vfs_request);
+int vfsreq_finish(struct vfs_request *, int ret);
+
/** Try to accept an enqueued request */
int vfs_backend_accept(struct vfs_backend *);
-int vfs_request_finish(struct vfs_request *, int ret);
-
-void vfs_request_cancel(struct vfs_request *, int ret);
void vfs_backend_refdown(struct vfs_backend *);
diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c
index 904f996..419d0f4 100644
--- a/src/kernel/vfs/root.c
+++ b/src/kernel/vfs/root.c
@@ -190,10 +190,10 @@ int vfs_root_handler(struct vfs_request *req) {
bool ready = true;
int ret = handle(req, &ready);
if (ready)
- return vfs_request_finish(req, ret);
+ return vfsreq_finish(req, ret);
else
return -1;
} else {
- return vfs_request_finish(req, -1);
+ return vfsreq_finish(req, -1);
}
}