From 6a71c766e60a9ac12876a0ea8a10c997df2507a3 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 7 Apr 2022 22:21:31 +0200 Subject: kernel/vfs: implement a vfs request queue --- src/kernel/proc.h | 5 ++++- src/kernel/syscalls.c | 4 ++-- src/kernel/vfs/request.c | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/kernel/proc.h b/src/kernel/proc.h index 6723e23..5e328aa 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -27,7 +27,10 @@ struct process { // saved value, meaning depends on .state union { int death_msg; // PS_DEAD - struct vfs_request pending_req; // PS_WAITS4FS + struct { + struct vfs_request req; + struct process *queue_next; + } waits4fs; // PS_WAITS4FS struct { char __user *buf; int max_len; diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index faa7ccc..daf7cac 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -215,8 +215,8 @@ int _syscall_fs_wait(char __user *buf, int max_len, struct fs_wait_response __us if (backend->queue) { // handle queued requests struct process *queued = backend->queue; - backend->queue = NULL; // TODO get the next queued proc - vfs_request_pass2handler(&queued->pending_req); + backend->queue = queued->waits4fs.queue_next; + vfs_request_pass2handler(&queued->waits4fs.req); } else { process_switch_any(); } diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 45a7ae7..0214ca7 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -10,10 +10,11 @@ int vfs_request_create(struct vfs_request req_) { struct vfs_request *req; int ret; process_current->state = PS_WAITS4FS; + process_current->waits4fs.queue_next = NULL; // the request is owned by the caller - process_current->pending_req = req_; - req = &process_current->pending_req; + process_current->waits4fs.req = req_; + req = &process_current->waits4fs.req; if (!req->backend) return vfs_request_finish(req, -1); @@ -26,8 +27,10 @@ int vfs_request_create(struct vfs_request req_) { case VFS_BACK_USER: if (req->backend->handler == NULL) { // backend isn't ready yet, join the queue - assert(req->backend->queue == NULL); // TODO implement a proper queue - req->backend->queue = process_current; + struct process **iter = &req->backend->queue; + while (*iter != NULL) + iter = &(*iter)->waits4fs.queue_next; + *iter = process_current; process_switch_any(); } else { vfs_request_pass2handler(req); -- cgit v1.2.3