• NeilBrown's avatar
    md/raid5: avoid races when changing cache size. · ed8b3124
    NeilBrown authored
    commit 2d5b569b upstream.
    
    Cache size can grow or shrink due to various pressures at
    any time.  So when we resize the cache as part of a 'grow'
    operation (i.e. change the size to allow more devices) we need
    to blocks that automatic growing/shrinking.
    
    So introduce a mutex.  auto grow/shrink uses mutex_trylock()
    and just doesn't bother if there is a blockage.
    Resizing the whole cache holds the mutex to ensure that
    the correct number of new stripes is allocated.
    
    This bug can result in some stripes not being freed when an
    array is stopped.  This leads to the kmem_cache not being
    freed and a subsequent array can try to use the same kmem_cache
    and get confused.
    
    Fixes: edbe83ab ("md/raid5: allow the stripe_cache to grow and shrink.")
    Signed-off-by: default avatarNeilBrown <neilb@suse.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    
    ed8b3124
raid5.c 220 KB