list: change locking discipline
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
2cf76fd225
commit
071a5651e0
11 changed files with 61 additions and 15 deletions
|
|
@ -30,6 +30,8 @@ int dirent_populate_children(dirent_t *dir)
|
|||
return n;
|
||||
}
|
||||
|
||||
list_lock(&inode->dirents);
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
dirent_t *dent = dents + i;
|
||||
dirent_t *insert = dirent_dup(dent);
|
||||
|
|
@ -45,6 +47,7 @@ int dirent_populate_children(dirent_t *dir)
|
|||
}
|
||||
}
|
||||
|
||||
list_unlock(&inode->dirents);
|
||||
write_unlock(&inode->rwlock);
|
||||
kfree(dents);
|
||||
return 0;
|
||||
|
|
@ -62,6 +65,7 @@ cleanup:
|
|||
item = next;
|
||||
}
|
||||
}
|
||||
list_unlock(&inode->dirents);
|
||||
write_unlock(&inode->rwlock);
|
||||
kfree(dents);
|
||||
return -ENOMEM;
|
||||
|
|
@ -121,6 +125,8 @@ inode_t *inode_create(void)
|
|||
|
||||
void inode_free(inode_t *inode)
|
||||
{
|
||||
list_lock(&inode->dirents);
|
||||
|
||||
while (inode->dirents.head) {
|
||||
list_item_t *item = inode->dirents.head;
|
||||
dirent_t *dent = item->ptr;
|
||||
|
|
@ -132,6 +138,8 @@ void inode_free(inode_t *inode)
|
|||
}
|
||||
}
|
||||
|
||||
list_unlock(&inode->dirents);
|
||||
|
||||
kfree(inode->data);
|
||||
slab_free(inode_slab, inode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,9 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags)
|
|||
|
||||
list_create(&m->children);
|
||||
|
||||
list_lock(&parent->children);
|
||||
m->child_link = list_insert(&parent->children, m);
|
||||
list_unlock(&parent->children);
|
||||
if (!m->child_link) {
|
||||
dirent_dec_ref(mp);
|
||||
kfree(m);
|
||||
|
|
@ -181,7 +183,9 @@ int vfs_umount(const char *path)
|
|||
return -EBUSY;
|
||||
}
|
||||
|
||||
list_lock(target->child_link->list);
|
||||
list_remove(target->child_link);
|
||||
list_unlock(target->child_link->list);
|
||||
dirent_dec_ref(target->mountpoint);
|
||||
kfree(target);
|
||||
|
||||
|
|
|
|||
|
|
@ -139,10 +139,13 @@ static int link(inode_t *parent_dir, inode_t *child, const char *name, dirent_t
|
|||
|
||||
new->inode = child;
|
||||
|
||||
list_lock(&parent_dir->dirents);
|
||||
if (!list_insert(&parent_dir->dirents, new)) {
|
||||
list_unlock(&parent_dir->dirents);
|
||||
dirent_free(new);
|
||||
return -ENOMEM;
|
||||
}
|
||||
list_unlock(&parent_dir->dirents);
|
||||
|
||||
*out = new;
|
||||
return 0;
|
||||
|
|
@ -153,17 +156,21 @@ static int unlink(inode_t *parent_dir, const char *name)
|
|||
if (!parent_dir || !name)
|
||||
return -EINVAL;
|
||||
|
||||
list_lock(&parent_dir->dirents);
|
||||
|
||||
list_item_t *item = parent_dir->dirents.head;
|
||||
while (item) {
|
||||
dirent_t *dent = item->ptr;
|
||||
if (!strcmp(dent->name, name)) {
|
||||
list_remove(item);
|
||||
list_unlock(&parent_dir->dirents);
|
||||
dirent_dec_ref(dent);
|
||||
return 0;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
list_unlock(&parent_dir->dirents);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -313,8 +313,13 @@ void vfs_register(struct fs_driver *fs)
|
|||
return;
|
||||
|
||||
memcpy(ins, fs, sizeof(*fs));
|
||||
if (!list_insert(&fs_type_list, ins))
|
||||
list_lock(&fs_type_list);
|
||||
if (!list_insert(&fs_type_list, ins)) {
|
||||
list_unlock(&fs_type_list);
|
||||
kfree(ins);
|
||||
} else {
|
||||
list_unlock(&fs_type_list);
|
||||
}
|
||||
}
|
||||
|
||||
void vfs_init(void)
|
||||
|
|
|
|||
Loading…
Reference in a new issue