* Minor cleanup, no functional change.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29480 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1123,53 +1123,56 @@ free_vnode(struct vnode* vnode, bool reenter)
|
|||||||
The caller must not hold the sVnodeMutex or the sMountMutex.
|
The caller must not hold the sVnodeMutex or the sMountMutex.
|
||||||
|
|
||||||
\param vnode the vnode.
|
\param vnode the vnode.
|
||||||
|
\param alwaysFree don't move this vnode into the unused list, but really
|
||||||
|
delete it if possible.
|
||||||
\param reenter \c true, if this function is called (indirectly) from within
|
\param reenter \c true, if this function is called (indirectly) from within
|
||||||
a file system.
|
a file system. This will be passed to file system hooks only.
|
||||||
\return \c B_OK, if everything went fine, an error code otherwise.
|
\return \c B_OK, if everything went fine, an error code otherwise.
|
||||||
*/
|
*/
|
||||||
static status_t
|
static status_t
|
||||||
dec_vnode_ref_count(struct vnode* vnode, bool alwaysFree, bool reenter)
|
dec_vnode_ref_count(struct vnode* vnode, bool alwaysFree, bool reenter)
|
||||||
{
|
{
|
||||||
mutex_lock(&sVnodeMutex);
|
MutexLocker locker(sVnodeMutex);
|
||||||
|
|
||||||
int32 oldRefCount = atomic_add(&vnode->ref_count, -1);
|
int32 oldRefCount = atomic_add(&vnode->ref_count, -1);
|
||||||
|
|
||||||
ASSERT_PRINT(oldRefCount > 0, "vnode %p\n", vnode);
|
ASSERT_PRINT(oldRefCount > 0, "vnode %p\n", vnode);
|
||||||
|
|
||||||
TRACE(("dec_vnode_ref_count: vnode %p, ref now %ld\n", vnode, vnode->ref_count));
|
TRACE(("dec_vnode_ref_count: vnode %p, ref now %ld\n", vnode,
|
||||||
|
vnode->ref_count));
|
||||||
|
|
||||||
if (oldRefCount == 1) {
|
if (oldRefCount != 1)
|
||||||
if (vnode->busy)
|
return B_OK;
|
||||||
panic("dec_vnode_ref_count: called on busy vnode %p\n", vnode);
|
|
||||||
|
|
||||||
bool freeNode = false;
|
if (vnode->busy)
|
||||||
|
panic("dec_vnode_ref_count: called on busy vnode %p\n", vnode);
|
||||||
|
|
||||||
// Just insert the vnode into an unused list if we don't need
|
bool freeNode = false;
|
||||||
// to delete it
|
|
||||||
if (vnode->remove || alwaysFree) {
|
// Just insert the vnode into an unused list if we don't need
|
||||||
|
// to delete it
|
||||||
|
if (vnode->remove || alwaysFree) {
|
||||||
|
vnode->busy = true;
|
||||||
|
freeNode = true;
|
||||||
|
} else {
|
||||||
|
list_add_item(&sUnusedVnodeList, vnode);
|
||||||
|
if (++sUnusedVnodes > kMaxUnusedVnodes
|
||||||
|
&& low_resource_state(
|
||||||
|
B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY)
|
||||||
|
!= B_NO_LOW_RESOURCE) {
|
||||||
|
// there are too many unused vnodes so we free the oldest one
|
||||||
|
// TODO: evaluate this mechanism
|
||||||
|
vnode = (struct vnode*)list_remove_head_item(&sUnusedVnodeList);
|
||||||
vnode->busy = true;
|
vnode->busy = true;
|
||||||
freeNode = true;
|
freeNode = true;
|
||||||
} else {
|
sUnusedVnodes--;
|
||||||
list_add_item(&sUnusedVnodeList, vnode);
|
|
||||||
if (++sUnusedVnodes > kMaxUnusedVnodes
|
|
||||||
&& low_resource_state(
|
|
||||||
B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY)
|
|
||||||
!= B_NO_LOW_RESOURCE) {
|
|
||||||
// there are too many unused vnodes so we free the oldest one
|
|
||||||
// TODO: evaluate this mechanism
|
|
||||||
vnode = (struct vnode*)list_remove_head_item(&sUnusedVnodeList);
|
|
||||||
vnode->busy = true;
|
|
||||||
freeNode = true;
|
|
||||||
sUnusedVnodes--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mutex_unlock(&sVnodeMutex);
|
locker.Unlock();
|
||||||
|
|
||||||
if (freeNode)
|
if (freeNode)
|
||||||
free_vnode(vnode, reenter);
|
free_vnode(vnode, reenter);
|
||||||
} else
|
|
||||||
mutex_unlock(&sVnodeMutex);
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -3712,12 +3715,9 @@ put_vnode(fs_volume* volume, ino_t vnodeID)
|
|||||||
extern "C" status_t
|
extern "C" status_t
|
||||||
remove_vnode(fs_volume* volume, ino_t vnodeID)
|
remove_vnode(fs_volume* volume, ino_t vnodeID)
|
||||||
{
|
{
|
||||||
struct vnode* vnode;
|
|
||||||
bool remove = false;
|
|
||||||
|
|
||||||
MutexLocker locker(sVnodeMutex);
|
MutexLocker locker(sVnodeMutex);
|
||||||
|
|
||||||
vnode = lookup_vnode(volume->id, vnodeID);
|
struct vnode* vnode = lookup_vnode(volume->id, vnodeID);
|
||||||
if (vnode == NULL)
|
if (vnode == NULL)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
@@ -3727,16 +3727,18 @@ remove_vnode(fs_volume* volume, ino_t vnodeID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vnode->remove = true;
|
vnode->remove = true;
|
||||||
|
bool removeUnpublished = false;
|
||||||
|
|
||||||
if (vnode->unpublished) {
|
if (vnode->unpublished) {
|
||||||
// prepare the vnode for deletion
|
// prepare the vnode for deletion
|
||||||
|
removeUnpublished = true;
|
||||||
vnode->busy = true;
|
vnode->busy = true;
|
||||||
remove = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
locker.Unlock();
|
locker.Unlock();
|
||||||
|
|
||||||
if (remove) {
|
if (removeUnpublished) {
|
||||||
// if the vnode hasn't been published yet, we delete it here
|
// If the vnode hasn't been published yet, we delete it here
|
||||||
atomic_add(&vnode->ref_count, -1);
|
atomic_add(&vnode->ref_count, -1);
|
||||||
free_vnode(vnode, true);
|
free_vnode(vnode, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user