• NeilBrown's avatar
    [PATCH] lockdep: simplify some aspects of bd_mutex nesting · 37be4124
    NeilBrown authored
    When we open (actually blkdev_get) a partition we need to also open (get) the
    whole device that holds the partition.  The involves some limited recursion.
    This patch tries to simplify some aspects of this.
    
    As well as opening the whole device, we need to increment ->bd_part_count when
    a partition is opened (this is used by rescan_partitions to avoid a rescan if
    any partition is active, as that would be confusing).
    
    The main change this patch makes is to move the inc/dec of bd_part_count into
    blkdev_{get,put} for the whole rather than doing it in blkdev_{get,put} for
    the partition.
    
    More specifically, we introduce __blkdev_get and __blkdev_put which do exactly
    what blkdev_{get,put} did, only with an extra "for_part" argument
    (blkget_{get,put} then call the __ version with a '0' for the extra argument).
    
    If for_part is 1, then the blkdev is being get(put) because a partition is
    being opened(closed) for the first(last) time, and so bd_part_count should be
    updated (on success).  The particular advantage of pushing this function down
    is that the bd_mutex lock (which is needed to update bd_part_count) is already
    held at the lower level.
    
    Note that this slightly changes the semantics of bd_part_count.  Instead of
    updating it whenever a partition is opened or released, it is now only updated
    on the first open or last release.  This is an adequate semantic as it is only
    ever tested for "== 0".
    
    Having introduced these functions we remove the current bd_part_count updates
    from do_open (which is really the body of blkdev_get) and call
    __blkdev_get(...  1).  Similarly in blkget_put we remove the old bd_part_count
    updates and call __blkget_put(..., 1).  This call is moved to the end of
    __blkdev_put to avoid nested locks of bd_mutex.
    
    Finally the mutex_lock on whole->bd_mutex in do_open can be removed.  It was
    only really needed to protect bd_part_count, and that is now managed (and
    protected) within the recursive call.
    
    The observation that bd_part_count is central to the locking issues, and the
    modifications to create __blkdev_put are from Peter Zijlstra.
    
    Cc: Ingo Molnar <mingo@elte.hu>
    Acked-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
    Signed-off-by: default avatarNeil Brown <neilb@suse.de>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    37be4124
block_dev.c 29.9 KB