loop: Only change blocksize when needed.

Return early in loop_set_block_size() if the requested block size is
identical to the one we already have; this avoids expensive calls to
freeze the block queue.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martijn Coenen <maco@android.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Martijn Coenen 2020-03-10 14:12:30 +01:00 committed by Jens Axboe
parent 596444e757
commit 7e81f99afd

View File

@ -1539,16 +1539,16 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
if (arg < 512 || arg > PAGE_SIZE || !is_power_of_2(arg)) if (arg < 512 || arg > PAGE_SIZE || !is_power_of_2(arg))
return -EINVAL; return -EINVAL;
if (lo->lo_queue->limits.logical_block_size != arg) { if (lo->lo_queue->limits.logical_block_size == arg)
return 0;
sync_blockdev(lo->lo_device); sync_blockdev(lo->lo_device);
kill_bdev(lo->lo_device); kill_bdev(lo->lo_device);
}
blk_mq_freeze_queue(lo->lo_queue); blk_mq_freeze_queue(lo->lo_queue);
/* kill_bdev should have truncated all the pages */ /* kill_bdev should have truncated all the pages */
if (lo->lo_queue->limits.logical_block_size != arg && if (lo->lo_device->bd_inode->i_mapping->nrpages) {
lo->lo_device->bd_inode->i_mapping->nrpages) {
err = -EAGAIN; err = -EAGAIN;
pr_warn("%s: loop%d (%s) has still dirty pages (nrpages=%lu)\n", pr_warn("%s: loop%d (%s) has still dirty pages (nrpages=%lu)\n",
__func__, lo->lo_number, lo->lo_file_name, __func__, lo->lo_number, lo->lo_file_name,