vfs: finish new locking scheme

This commit is contained in:
Matheus
2024-08-27 21:02:12 -03:00
parent 8f6bc6c4c1
commit f55b51a06d
8 changed files with 168 additions and 128 deletions
+4 -1
View File
@@ -99,7 +99,10 @@ syscallret_t syscall_openat(context_t *context, int dirfd, char *path, int flags
ret.ret = newfd;
cleanup:
VOP_UNLOCK(vnode);
if (vnode)
VOP_UNLOCK(vnode);
cleanup_nounlock:
if (vnode && ret.errno) {
vfs_close(vnode, fileflagstovnodeflags(flags));
+1 -38
View File
@@ -18,8 +18,6 @@ syscallret_t syscall_renameat(context_t *context, int olddirfd, char *uoldpath,
return ret;
}
char *oldcomponent = NULL;
char *newcomponent = NULL;
char *oldpath = alloc(oldpathlen + 1);
if (oldpath == NULL) {
ret.errno = ENOMEM;
@@ -42,54 +40,19 @@ syscallret_t syscall_renameat(context_t *context, int olddirfd, char *uoldpath,
file_t *oldfile = NULL;
vnode_t *newdirnode = NULL;
file_t *newfile = NULL;
vnode_t *targetdirnode = NULL;
vnode_t *sourcedirnode = NULL;
ret.errno = dirfd_enter(oldpath, olddirfd, &oldfile, &olddirnode);
if (ret.errno)
goto cleanup;
ret.errno = dirfd_enter(newpath, newdirfd, &newfile, &newdirnode);
if (ret.errno)
goto cleanup;
oldcomponent = alloc(strlen(oldpath) + 1);
newcomponent = alloc(strlen(newpath) + 1);
if (oldcomponent == NULL && newcomponent == NULL)
goto cleanup;
// TODO deadlocks.
ret.errno = vfs_lookup(&sourcedirnode, olddirnode, oldpath, oldcomponent, VFS_LOOKUP_NOLINK | VFS_LOOKUP_PARENT);
if (ret.errno)
goto cleanup;
ret.errno = vfs_lookup(&targetdirnode, newdirnode, newpath, newcomponent, VFS_LOOKUP_NOLINK | VFS_LOOKUP_PARENT);
if (ret.errno) {
VOP_UNLOCK(sourcedirnode);
goto cleanup;
}
ret.errno = VOP_RENAME(sourcedirnode, oldcomponent, targetdirnode, newcomponent, flags);
ret.errno = vfs_rename(olddirnode, oldpath, newdirnode, newpath, flags);
ret.ret = ret.errno ? -1 : 0;
VOP_UNLOCK(targetdirnode);
VOP_UNLOCK(sourcedirnode);
cleanup:
if (targetdirnode)
VOP_RELEASE(targetdirnode);
if (sourcedirnode)
VOP_RELEASE(sourcedirnode);
if (oldcomponent)
free(oldcomponent);
if (newcomponent)
free(newcomponent);
if (olddirnode)
dirfd_leave(olddirnode, oldfile);
+1 -16
View File
@@ -40,25 +40,10 @@ syscallret_t syscall_unlinkat(context_t *, int dirfd, char *upath, int flags) {
if (ret.errno)
goto cleanup;
// TODO rmdir flag
vnode_t *node = NULL;
ret.errno = vfs_lookup(&node, dirnode, path, component, VFS_LOOKUP_NOLINK | VFS_LOOKUP_PARENT);
if (ret.errno)
goto cleanup;
ret.errno = VOP_UNLINK(node, component, &_cpu()->thread->proc->cred);
ret.errno = vfs_unlink(dirnode, path);
ret.ret = ret.errno ? -1 : 0;
// locked by vfs_lookup
VOP_UNLOCK(node);
cleanup:
if (component)
free(component);
if (node)
VOP_RELEASE(node);
if (dirnode)
dirfd_leave(dirnode, file);