summaryrefslogtreecommitdiff
path: root/src/kernel/vfs/request.c
diff options
context:
space:
mode:
authordzwdz2022-05-05 18:31:56 +0200
committerdzwdz2022-05-05 18:31:56 +0200
commite7d6d031e54ef1b1c7b589648a27eea84994549f (patch)
treeedd71237b0112a7ad2e29702b7802af83c221a5c /src/kernel/vfs/request.c
parent60a5c52c407db5f88df82c0dfce425d0faab6831 (diff)
kernel/vfs: rename the vfsreq funcs, merge vfsreq_finish & vfsreq_cancel
Diffstat (limited to 'src/kernel/vfs/request.c')
-rw-r--r--src/kernel/vfs/request.c93
1 files changed, 37 insertions, 56 deletions
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) {