kernel/fs: Add assertions to acquire_vnode and put_vnode.
* panic under KDEBUG if the node does not exist. * panic always if the node reference count was 0. We don't handle 0 -> 1 transitions here, and it doesn't make sense to acquire "another" reference to a node you haven't referenced. Would have caught the ext2 use-after-free fixed in an earlier commit.
This commit is contained in:
@@ -3864,10 +3864,17 @@ acquire_vnode(fs_volume* volume, ino_t vnodeID)
|
|||||||
ReadLocker nodeLocker(sVnodeLock);
|
ReadLocker nodeLocker(sVnodeLock);
|
||||||
|
|
||||||
struct vnode* vnode = lookup_vnode(volume->id, vnodeID);
|
struct vnode* vnode = lookup_vnode(volume->id, vnodeID);
|
||||||
if (vnode == NULL)
|
if (vnode == NULL) {
|
||||||
|
KDEBUG_ONLY(panic("acquire_vnode(%p, %" B_PRIdINO "): not found!", volume, vnodeID));
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inc_vnode_ref_count(vnode) == 0) {
|
||||||
|
// It isn't valid to acquire another reference to a vnode that
|
||||||
|
// you don't already have a reference to, so this should never happen.
|
||||||
|
panic("acquire_vnode(%p, %" B_PRIdINO "): node wasn't used!", volume, vnodeID);
|
||||||
|
}
|
||||||
|
|
||||||
inc_vnode_ref_count(vnode);
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3881,8 +3888,10 @@ put_vnode(fs_volume* volume, ino_t vnodeID)
|
|||||||
vnode = lookup_vnode(volume->id, vnodeID);
|
vnode = lookup_vnode(volume->id, vnodeID);
|
||||||
rw_lock_read_unlock(&sVnodeLock);
|
rw_lock_read_unlock(&sVnodeLock);
|
||||||
|
|
||||||
if (vnode == NULL)
|
if (vnode == NULL) {
|
||||||
|
KDEBUG_ONLY(panic("put_vnode(%p, %" B_PRIdINO "): not found!", volume, vnodeID));
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
dec_vnode_ref_count(vnode, false, true);
|
dec_vnode_ref_count(vnode, false, true);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
Reference in New Issue
Block a user