• Mike Snitzer's avatar
    dm: always manage discard support in terms of max_hw_discard_sectors · 825d8bbd
    Mike Snitzer authored
    Commit 4f563a64 ("block: add a max_user_discard_sectors queue
    limit") changed block core to set max_discard_sectors to:
     min(lim->max_hw_discard_sectors, lim->max_user_discard_sectors)
    
    Since commit 1c0e7202 ("dm: use queue_limits_set") it was reported
    dm-thinp was failing in a few fstests (generic/347 and generic/405)
    with the first WARN_ON_ONCE in dm_cell_key_has_valid_range() being
    reported, e.g.:
    WARNING: CPU: 1 PID: 30 at drivers/md/dm-bio-prison-v1.c:128 dm_cell_key_has_valid_range+0x3d/0x50
    
    blk_set_stacking_limits() sets max_user_discard_sectors to UINT_MAX,
    so given how block core now sets max_discard_sectors (detailed above)
    it follows that blk_stack_limits() stacks up the underlying device's
    max_hw_discard_sectors and max_discard_sectors is set to match it. If
    max_hw_discard_sectors exceeds dm's BIO_PRISON_MAX_RANGE, then
    dm_cell_key_has_valid_range() will trigger the warning with:
    WARN_ON_ONCE(key->block_end - key->block_begin > BIO_PRISON_MAX_RANGE)
    
    Aside from this warning, the discard will fail.  Fix this and other DM
    issues by governing discard support in terms of max_hw_discard_sectors
    instead of max_discard_sectors.
    Reported-by: default avatarTheodore Ts'o <tytso@mit.edu>
    Fixes: 1c0e7202 ("dm: use queue_limits_set")
    Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
    825d8bbd
dm-clone-target.c 54.4 KB