diff options
author | dzwdz | 2022-05-02 18:58:57 +0200 |
---|---|---|
committer | dzwdz | 2022-05-02 18:58:57 +0200 |
commit | c38fa859a6fb3e9fce736ead57ee776fe433a0d0 (patch) | |
tree | 59dca00c7e9112b53c5ade9e7114d858b5dcaa7a /src/kernel/vfs/request.c | |
parent | 8513ae3c3e83ec8835bc0d1355284a9ddd928693 (diff) |
kernel/vfs: always separately allocate the request object
Diffstat (limited to 'src/kernel/vfs/request.c')
-rw-r--r-- | src/kernel/vfs/request.c | 58 |
1 files changed, 23 insertions, 35 deletions
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 99d2e2c..1f3193f 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -7,22 +7,13 @@ #include <shared/mem.h> int vfs_request_create(struct vfs_request req_) { - struct vfs_request *req; - - if (req_.caller) { - /* if the request has an explicit caller (isn't a close() call) - * it's owned by said caller - * - * it would be simpler if all requests were owned by the backend. - * i might end up changing that eventually. TODO? */ - process_transition(req_.caller, PS_WAITS4FS); - req_.caller->waits4fs.req = req_; - req = &req_.caller->waits4fs.req; - } else { - /* requests without explicit callers (close() calls) are owned by the - * backend, and freed in vfs_request_finish or vfs_request_cancel */ - req = kmalloc(sizeof *req); - memcpy(req, &req_, sizeof *req); + struct vfs_request *req = kmalloc(sizeof *req); + memcpy(req, &req_, sizeof *req); + /* freed in vfs_request_finish or vfs_request_cancel */ + + if (req->caller) { + process_transition(req->caller, PS_WAITS4FS); + req->caller->waits4fs.req = req; } if (!req->backend || !req->backend->potential_handlers) @@ -104,31 +95,28 @@ int vfs_request_finish(struct vfs_request *req, int ret) { if (req->input.kern) kfree(req->input.buf_kern); - if (!req->caller) { - kfree(req); // ok, this stinks. see comment at top of file - return 0; + if (req->caller) { + assert(req->caller->state == PS_WAITS4FS || req->caller->state == PS_WAITS4IRQ); + regs_savereturn(&req->caller->regs, ret); + process_transition(req->caller, PS_RUNNING); } - assert(req->caller->state == PS_WAITS4FS || req->caller->state == PS_WAITS4IRQ); - regs_savereturn(&req->caller->regs, ret); - process_transition(req->caller, PS_RUNNING); + kfree(req); return ret; } void vfs_request_cancel(struct vfs_request *req, int ret) { - if (!req->caller) { - kfree(req); - return; - } - - assert(req->caller->state == PS_WAITS4FS); + if (req->caller) { + assert(req->caller->state == PS_WAITS4FS); - if (req->input.kern) - kfree(req->input.buf_kern); + if (req->input.kern) + kfree(req->input.buf_kern); - // 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); + // 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); + } + kfree(req); } |