summaryrefslogtreecommitdiff
path: root/src/kernel/vfs/request.c
diff options
context:
space:
mode:
authordzwdz2022-05-04 13:49:38 +0200
committerdzwdz2022-05-04 13:49:38 +0200
commit3bf07641ee5ba1c6ec56b81a7f34abe1267d3ac1 (patch)
tree2eee4442a5aba9fe3a29078a2e8187d999af83a3 /src/kernel/vfs/request.c
parent9692ed2f93777e1060837b97687509f8a22c2b60 (diff)
kernel: refcount vfs_backend
what a mess
Diffstat (limited to 'src/kernel/vfs/request.c')
-rw-r--r--src/kernel/vfs/request.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index 1f3193f..edb1fce 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -11,6 +11,9 @@ int vfs_request_create(struct vfs_request req_) {
memcpy(req, &req_, sizeof *req);
/* freed in vfs_request_finish or vfs_request_cancel */
+ if (req->backend)
+ req->backend->refcount++;
+
if (req->caller) {
process_transition(req->caller, PS_WAITS4FS);
req->caller->waits4fs.req = req;
@@ -87,6 +90,7 @@ int vfs_request_finish(struct vfs_request *req, int ret) {
struct handle *backing = handle_init(HANDLE_FILE);
backing->file.backend = req->backend;
+ req->backend->refcount++;
backing->file.id = ret;
req->caller->handles[handle] = backing;
ret = handle;
@@ -101,11 +105,13 @@ int vfs_request_finish(struct vfs_request *req, int ret) {
process_transition(req->caller, PS_RUNNING);
}
+ vfs_backend_refdown(req->backend);
kfree(req);
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);
@@ -118,5 +124,16 @@ void vfs_request_cancel(struct vfs_request *req, int ret) {
regs_savereturn(&req->caller->regs, ret);
process_transition(req->caller, PS_RUNNING);
}
+
+ vfs_backend_refdown(req->backend);
kfree(req);
}
+
+void vfs_backend_refdown(struct vfs_backend *b) {
+ assert(b);
+ assert(b->refcount > 0);
+ if (--(b->refcount) > 0) return;
+
+ assert(!b->queue);
+ kfree(b);
+}