kernel/vfs: Fix some potential edge cases around vnode creation.

Noticed as part of investigating #18805.

Change-Id: I158126979996f8527728d073ac2101f2f834bfb2
This commit is contained in:
Augustin Cavalier 2024-03-16 15:57:17 -04:00
parent 5e20a59fa2
commit 99e6fd949b

View File

@ -2131,7 +2131,7 @@ vnode_path_to_vnode(struct vnode* vnode, char* path, bool traverseLeafLink,
ino_t* _parentID, char* leafName)
{
FUNCTION(("vnode_path_to_vnode(vnode = %p, path = %s)\n", vnode, path));
ASSERT(!_vnode.IsSet() || _vnode.Get() != vnode);
ASSERT(!_vnode.IsSet());
if (path == NULL) {
put_vnode(vnode);
@ -2146,7 +2146,6 @@ vnode_path_to_vnode(struct vnode* vnode, char* path, bool traverseLeafLink,
status_t status = B_OK;
ino_t lastParentID = vnode->id;
while (true) {
struct vnode* nextVnode;
char* nextPath;
TRACE(("vnode_path_to_vnode: top of loop. p = %p, p = '%s'\n", path,
@ -2181,9 +2180,8 @@ vnode_path_to_vnode(struct vnode* vnode, char* path, bool traverseLeafLink,
}
if (Vnode* coveredVnode = get_covered_vnode(vnode)) {
nextVnode = coveredVnode;
put_vnode(vnode);
vnode = nextVnode;
vnode = coveredVnode;
}
}
@ -2199,6 +2197,7 @@ vnode_path_to_vnode(struct vnode* vnode, char* path, bool traverseLeafLink,
// Tell the filesystem to get the vnode of this path component (if we
// got the permission from the call above)
struct vnode* nextVnode;
if (status == B_OK)
status = lookup_dir_entry(vnode, path, &nextVnode);
@ -2293,6 +2292,8 @@ vnode_path_to_vnode(struct vnode* vnode, char* path, bool traverseLeafLink,
if (status != B_OK) {
if (leafName != NULL)
_vnode.SetTo(nextVnode);
else
put_vnode(nextVnode);
put_vnode(vnode);
return status;
}
@ -5421,6 +5422,7 @@ create_vnode(struct vnode* directory, const char* name, int openMode,
}
inc_vnode_ref_count(directory);
dirPutter.Unset();
status = vnode_path_to_vnode(directory, clonedName, true, 0,
kernel, vnode, NULL, clonedName);
if (status != B_OK) {