Changeset 24548

Show
Ignore:
Timestamp:
03/24/08 00:15:42 (2 months ago)
Author:
bonefish
Message:
Applied change proposed in #1917 after encountering the bug the third
time. Releasing the cache's store reference while holding the cache lock
could reverse the usual locking order -- the VFS could potentially call
the remove_vnode() or put_vnode() FS hook, which in turn could use the
file cache, thus resulting in a deadlock. Now we release the store ref
before locking the cache.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • haiku/trunk/src/system/kernel/vm/vm_cache.cpp

    r23334 r24548  
    546546        ASSERT_LOCKED_MUTEX(&consumer->lock); 
    547547 
     548        // Remove the store ref before locking the cache. Otherwise we'd call into 
     549        // the VFS while holding the cache lock, which would reverse the usual 
     550        // locking order. 
     551        if (cache->store->ops->release_ref) 
     552                cache->store->ops->release_ref(cache->store); 
     553 
    548554        // remove the consumer from the cache, but keep its reference until later 
    549555        mutex_lock(&cache->lock); 
    550556        list_remove_item(&cache->consumers, consumer); 
    551557        consumer->source = NULL; 
    552  
    553         if (cache->store->ops->release_ref) 
    554                 cache->store->ops->release_ref(cache->store); 
    555558 
    556559        if (cache->areas == NULL && cache->source != NULL