diff options
author | dzwdz | 2024-07-07 17:42:18 +0200 |
---|---|---|
committer | dzwdz | 2024-07-07 17:42:18 +0200 |
commit | 8138ba97608ff0cd4e443994390f277eca3d7b28 (patch) | |
tree | 59b6066071f50aa0e7dc209cc5f7ef3433db1987 /src/kernel/vfs/request.c | |
parent | a4975c459dec3a37e1634ad9b25c05f4caa4f1b0 (diff) |
kernel/vfs: split vfs_backend_refdown into two functions
Diffstat (limited to 'src/kernel/vfs/request.c')
-rw-r--r-- | src/kernel/vfs/request.c | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index e3f0316..8fe0114 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -80,11 +80,13 @@ void vfsreq_finish(VfsReq *req, char __user *stored, long ret, assert((size_t)ret <= req->output.len); } - if (req->input.kern) + if (req->input.kern) { kfree(req->input.buf_kern); + } - if (req->backend) - vfs_backend_refdown(req->backend, true); + if (req->backend) { + vfsback_userdown(req->backend); + } if (req->caller) { assert(req->caller->state == PS_WAITS4FS); @@ -159,26 +161,28 @@ static void vfs_backend_user_accept(VfsReq *req) { return; } -void vfs_backend_refdown(VfsBackend *b, bool use) { - size_t *field = use ? &b->usehcnt : &b->provhcnt; - assert(b); - assert(0 < *field); - *field -= 1; - - if (b->provhcnt == 0 && use == false) { - VfsReq *q = b->queue; - while (q) { - VfsReq *q2 = q->queue_next; - vfsreq_finish_short(q, -1); - q = q2; - } - b->queue = NULL; +static void +vfsback_checkfree(VfsBackend *b) +{ + if (b->usehcnt == 0 && b->provhcnt == 0) { + assert(!b->queue); + kfree(b); } - if (b->usehcnt == 0 && use == true) { +} + +void +vfsback_userdown(VfsBackend *b) +{ + assert(b); + assert(0 < b->usehcnt); + b->usehcnt--; + if (b->usehcnt == 0) { if (!b->is_user && b->kern.cleanup) { b->kern.cleanup(b); } if (b->is_user && b->user.handler) { + /* tell the process that the filesystem won't receive any more + * requests */ Proc *p = b->user.handler; b->user.handler = NULL; assert(p->state == PS_WAITS4REQUEST); @@ -186,8 +190,24 @@ void vfs_backend_refdown(VfsBackend *b, bool use) { proc_setstate(p, PS_RUNNING); } } - if (b->usehcnt == 0 && b->provhcnt == 0) { - assert(!b->queue); - kfree(b); + vfsback_checkfree(b); +} + +void +vfsback_provdown(VfsBackend *b) +{ + assert(b); + assert(0 < b->provhcnt); + b->provhcnt--; + if (b->provhcnt == 0) { + /* discard everything in the queue */ + VfsReq *q = b->queue; + while (q) { + VfsReq *q2 = q->queue_next; + vfsreq_finish_short(q, -1); + q = q2; + } + b->queue = NULL; } + vfsback_checkfree(b); } |