summaryrefslogtreecommitdiff
path: root/src/kernel/vfs/request.c
diff options
context:
space:
mode:
authordzwdz2024-07-14 19:40:31 +0200
committerdzwdz2024-07-14 19:40:31 +0200
commit881be872675e4cff153c27c641980451c4a3f479 (patch)
treea374913fc7f1fcbd1d380719d695bf5f67b83e56 /src/kernel/vfs/request.c
parent6fe8073de975ad7722043f9173fec068178e2eac (diff)
kernel: make the adhoc VfsQueue queues use ReqQueue instead
I'm still not sure if I should use sys/queue.h for this. But yeah, this is more consistent, and it will also let me switch over to O(1) insertions later on.
Diffstat (limited to 'src/kernel/vfs/request.c')
-rw-r--r--src/kernel/vfs/request.c58
1 files changed, 24 insertions, 34 deletions
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index 8f44afb..58e2987 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -52,8 +52,7 @@ vfsreq_dispatchcopy(VfsReq tmpl)
vfsreq_finish_short(req, -EINVAL);
return;
}
- assert(req->queue_next == NULL);
- assert(req->postqueue_next == NULL);
+ assert(req->reqqueue_next == NULL);
if (backend == NULL) {
/* null mount - probably never had a real backend */
@@ -111,8 +110,7 @@ vfsreq_finish(VfsReq *req, char __user *stored, long ret, int flags, Proc *handl
vfsback_userdown(req->backend);
}
- assert(req->queue_next == NULL);
- assert(req->postqueue_next == NULL);
+ assert(req->reqqueue_next == NULL);
if (req->caller) {
assert(req->caller->state == PS_WAITS4FS);
@@ -134,17 +132,11 @@ vfsback_useraccept(VfsReq *req)
backend = req->backend;
assert(backend);
assert(backend->is_user);
- if (backend->provhcnt == 0) {
+ if (backend->user.provhcnt == 0) {
vfsreq_finish_short(req, -EPIPE);
return;
} else if (backend->user.handler == NULL) {
- /* queue the request up */
- // TODO use postqueue
- VfsReq **it = &backend->queue;
- while (*it != NULL) { /* find a free spot in queue */
- it = &(*it)->queue_next;
- }
- *it = req;
+ reqqueue_join(&backend->user.queue, req);
return;
}
@@ -194,8 +186,8 @@ vfsback_useraccept(VfsReq *req)
static void
vfsback_checkfree(VfsBackend *b)
{
- if (b->usehcnt == 0 && b->provhcnt == 0) {
- assert(!b->queue);
+ if (b->is_user && b->usehcnt == 0 && b->user.provhcnt == 0) {
+ assert(b->user.queue.head == NULL);
kfree(b);
}
}
@@ -227,54 +219,52 @@ void
vfsback_provdown(VfsBackend *b)
{
assert(b);
- assert(0 < b->provhcnt);
- b->provhcnt--;
- if (b->provhcnt == 0) {
+ assert(b->is_user);
+ assert(0 < b->user.provhcnt);
+ b->user.provhcnt--;
+ if (b->user.provhcnt == 0) {
+ assert(b->is_user);
/* discard everything in the queue */
- VfsReq *q = b->queue;
- while (q) {
- VfsReq *q2 = q->queue_next;
- q->queue_next = NULL;
+ VfsReq *q;
+ while ((q = reqqueue_pop(&b->user.queue))) {
vfsreq_finish_short(q, -EPIPE);
- q = q2;
}
- b->queue = NULL;
}
vfsback_checkfree(b);
}
void
-postqueue_init(ReqQueue *q)
+reqqueue_init(ReqQueue *q)
{
q->head = NULL;
}
void
-postqueue_join(ReqQueue *q, VfsReq *req)
+reqqueue_join(ReqQueue *q, VfsReq *req)
{
- if (req->postqueue_next)
+ if (req->reqqueue_next)
panic_invalid_state();
VfsReq **it = &q->head;
while (*it != NULL) {
- it = &(*it)->postqueue_next;
+ it = &(*it)->reqqueue_next;
}
*it = req;
}
VfsReq *
-postqueue_pop(ReqQueue *q)
+reqqueue_pop(ReqQueue *q)
{
VfsReq *req = q->head;
if (req) {
- q->head = req->postqueue_next;
- req->postqueue_next = NULL;
+ q->head = req->reqqueue_next;
+ req->reqqueue_next = NULL;
}
return req;
}
void
-postqueue_ringreadall(ReqQueue *q, ring_t *r)
+reqqueue_ringreadall(ReqQueue *q, ring_t *r)
{
VfsReq **queue = &q->head; /* whatever */
VfsReq *req;
@@ -283,15 +273,15 @@ postqueue_ringreadall(ReqQueue *q, ring_t *r)
if (ring_used(r) == 0) return;
/* read as much as the biggest request wants */
- for (req = *queue; req; req = req->postqueue_next)
+ for (req = *queue; req; req = req->reqqueue_next)
mlen = max(mlen, req->output.len);
mlen = min(mlen, sizeof tmp);
mlen = ring_get(r, tmp, mlen);
while (*queue) {
req = *queue;
- *queue = req->postqueue_next;
- req->postqueue_next = NULL;
+ *queue = req->reqqueue_next;
+ req->reqqueue_next = NULL;
size_t ret = min(mlen, req->output.len);
assert(req->type == VFSOP_READ);