Skip to content
Snippets Groups Projects
Commit 7e98a699 authored by Ming Lei's avatar Ming Lei
Browse files

virtio_blk: fix the discard_granularity and discard_alignment queue limits

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083917



commit 62952cc5
Author: Christoph Hellwig <hch@lst.de>
Date:   Mon Apr 18 06:53:07 2022 +0200

    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: 1f23816b ("virtio_blk: add discard and write zeroes support")
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
    Link: https://lore.kernel.org/r/20220418045314.360785-5-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>

Signed-off-by: default avatarMing Lei <ming.lei@redhat.com>
parent 130594b2
No related merge requests found
......@@ -816,11 +816,12 @@ static int virtblk_probe(struct virtio_device *vdev)
blk_queue_io_opt(q, blk_size * opt_io_size);
if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) {
q->limits.discard_granularity = blk_size;
virtio_cread(vdev, struct virtio_blk_config,
discard_sector_alignment, &v);
q->limits.discard_alignment = v ? v << SECTOR_SHIFT : 0;
if (v)
q->limits.discard_granularity = v << SECTOR_SHIFT;
else
q->limits.discard_granularity = blk_size;
virtio_cread(vdev, struct virtio_blk_config,
max_discard_sectors, &v);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment