• Mikulas Patocka's avatar
    dm: always hold bdev reference · 32a926da
    Mikulas Patocka authored
    Fix a potential deadlock when creating multiple snapshots by holding a
    reference to struct block_device for the whole lifecycle of every dm
    device instead of obtaining it independently at each point it is needed.
    
    bdget_disk() was called while the device was being suspended, in
    dm_suspend().  However there could be other devices already suspended,
    for example when creating additional snapshots of a device. bdget_disk()
    can wait for IO and allocate memory resulting in waiting for the
    already-suspended device - deadlock.
    
    This patch changes the code so that it gets the reference to struct
    block_device when struct mapped_device is allocated and initialized in
    alloc_dev() where it is always OK to allocate memory or wait for I/O.
    It drops the reference when it is destroyed in free_dev().  Thus there
    is no call to bdget_disk() while any device is suspended.
    
    Previously unlock_fs() was called only if bdev was held.  Now it is
    called unconditionally, but the superfluous calls are harmless because
    it returns immediately if the filesystem was not previously frozen.
    
    This patch also now allows the device size to be changed in a
    noflush suspend because the bdev is held.  This has no adverse effect.
    Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
    Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
    32a926da
dm.c 37 KB