lock: merge spinlock and mtx locks into one

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-08-13 14:19:10 -04:00
commit 2076f1dae1
Signed by: michaelsshaw
GPG key ID: 5A5E0FB20708A9E7
32 changed files with 158 additions and 169 deletions

View file

@ -8,7 +8,7 @@
#include <lib/string.h>
static struct mount *root_mount = NULL;
static spinlock_t mount_lock = 0;
static lock_t mount_lock = 0;
fs_t *vfs_get_root(void)
{
@ -24,19 +24,19 @@ struct mount *vfs_get_root_mount(void)
struct mount *mount_find_child(struct mount *parent, dirent_t *dent)
{
spinlock_acquire(&mount_lock);
spin_lock(&mount_lock);
list_item_t *item = parent->children.head;
while (item) {
struct mount *m = item->ptr;
if (m->mountpoint == dent) {
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return m;
}
item = item->next;
}
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return NULL;
}
@ -65,16 +65,16 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags)
return -EINVAL;
if (!path) {
spinlock_acquire(&mount_lock);
spin_lock(&mount_lock);
if (root_mount) {
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return -EBUSY;
}
struct mount *m = kzalloc(sizeof(*m), ALLOC_KERN);
if (!m) {
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return -ENOMEM;
}
@ -86,7 +86,7 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags)
list_create(&m->children);
root_mount = m;
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return 0;
}
@ -101,14 +101,14 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags)
return -ENOTDIR;
}
spinlock_acquire(&mount_lock);
spin_lock(&mount_lock);
list_item_t *item = parent->children.head;
while (item) {
struct mount *m = item->ptr;
if (m->mountpoint == mp) {
dirent_dec_ref(mp);
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return -EBUSY;
}
item = item->next;
@ -117,7 +117,7 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags)
struct mount *m = kzalloc(sizeof(*m), ALLOC_KERN);
if (!m) {
dirent_dec_ref(mp);
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return -ENOMEM;
}
@ -134,11 +134,11 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags)
if (!m->child_link) {
dirent_dec_ref(mp);
kfree(m);
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return -ENOMEM;
}
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return 0;
}
@ -153,7 +153,7 @@ int vfs_umount(const char *path)
if (res < 0)
return res;
spinlock_acquire(&mount_lock);
spin_lock(&mount_lock);
struct mount *target = NULL;
list_item_t *item = parent->children.head;
@ -169,17 +169,17 @@ int vfs_umount(const char *path)
dirent_dec_ref(mp);
if (!target) {
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return -EINVAL;
}
if (target == root_mount) {
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return -EINVAL;
}
if (target->children.head) {
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return -EBUSY;
}
@ -189,6 +189,6 @@ int vfs_umount(const char *path)
dirent_dec_ref(target->mountpoint);
kfree(target);
spinlock_release(&mount_lock);
spin_unlock(&mount_lock);
return 0;
}