Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

virtio_blk: fix the discard_granularity and discard_alignment queue limits

The discard_alignment queue limit is named a bit misleading means the
offset into the block device at which the discard granularity starts.

On the other hand the discard_sector_alignment from the virtio 1.1 looks
similar to what Linux uses as discard granularity (even if not very well
described):

"discard_sector_alignment can be used by OS when splitting a request
based on alignment. "

And at least qemu does set it to the discard granularity.

So stop setting the discard_alignment and use the virtio
discard_sector_alignment to set the discard granularity.

Fixes: 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20220418045314.360785-5-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
62952cc5 fb749a87

+4 -3
+4 -3
drivers/block/virtio_blk.c
··· 867 867 blk_queue_io_opt(q, blk_size * opt_io_size); 868 868 869 869 if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) { 870 - q->limits.discard_granularity = blk_size; 871 - 872 870 virtio_cread(vdev, struct virtio_blk_config, 873 871 discard_sector_alignment, &v); 874 - q->limits.discard_alignment = v ? v << SECTOR_SHIFT : 0; 872 + if (v) 873 + q->limits.discard_granularity = v << SECTOR_SHIFT; 874 + else 875 + q->limits.discard_granularity = blk_size; 875 876 876 877 virtio_cread(vdev, struct virtio_blk_config, 877 878 max_discard_sectors, &v);