• Ming Lei's avatar
    block: loop: set discard granularity and alignment for block device backed loop · bcb21c8c
    Ming Lei authored
    In case of block device backend, if the backend supports write zeros, the
    loop device will set queue flag of QUEUE_FLAG_DISCARD. However,
    limits.discard_granularity isn't setup, and this way is wrong,
    see the following description in Documentation/ABI/testing/sysfs-block:
    
    	A discard_granularity of 0 means that the device does not support
    	discard functionality.
    
    Especially 9b15d109 ("block: improve discard bio alignment in
    __blkdev_issue_discard()") starts to take q->limits.discard_granularity
    for computing max discard sectors. And zero discard granularity may cause
    kernel oops, or fail discard request even though the loop queue claims
    discard support via QUEUE_FLAG_DISCARD.
    
    Fix the issue by setup discard granularity and alignment.
    
    Fixes: c52abf56 ("loop: Better discard support for block devices")
    Signed-off-by: default avatarMing Lei <ming.lei@redhat.com>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    Acked-by: default avatarColy Li <colyli@suse.de>
    Cc: Hannes Reinecke <hare@suse.com>
    Cc: Xiao Ni <xni@redhat.com>
    Cc: Martin K. Petersen <martin.petersen@oracle.com>
    Cc: Evan Green <evgreen@chromium.org>
    Cc: Gwendal Grignou <gwendal@chromium.org>
    Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
    Cc: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
    bcb21c8c
loop.c 59.6 KB