[Devel] [PATCH hci-8.2 v3 4/4] drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD

Konstantin Khorenko khorenko at virtuozzo.com
Wed Nov 25 15:32:09 MSK 2026


I won't apply this version, please send v4 with the changes below.

- One form of the op test: item 3.
- Pass the backend to vhost_blk_parse_segment() once: item 4.
- Message fixes: item 5 of the cover letter reply.

On Wed, 25 Nov 2026 12:57:03 +0100, Alexander Ivanov wrote:
> +	if (err && op_is_discard(req->bi_opf) &&
> +	    (err == -EOPNOTSUPP || !bdev_max_discard_sectors(bdev)))
> +		err = 0;
>  	if (err && (req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES &&

Item 3: two forms of the same test side by side, here and in
vhost_blk_bio_make(). v1 asked for one; use
(req->bi_opf & REQ_OP_MASK) == REQ_OP_DISCARD next to the
WRITE_ZEROES test.

> +static int vhost_blk_parse_segment(struct vhost_blk_req *req,
> +				   struct block_device *bdev,

Item 4: the function still looks up f itself, and both callers take f
and bdev only to pass bdev down. Get bdev from f here and drop the
parameter and the callers' locals.

> A discard is a hint, and the guest takes the limits from the VMM, not
> from the backend. So the range is not checked against the backend
> discard limit: the bio gets split by it. As QEMU does, complete the

Item 5: the block layer splitting the bio is why the limit is not
checked; the hint is why the request completes with VIRTIO_BLK_S_OK
without a backend discard. Keep the two reasons apart.

> max_discard_sectors at 8388607 so that the range fits in one bio. QEMU

Item 5: 8388607 is not a multiple of 8, so on a 4K backend a range of
exactly that size fails the alignment check with IOERR: say "rounded
down to the logical block size". Also say that the VMM must not offer
VIRTIO_BLK_F_DISCARD for a drive whose discards are to be ignored
(QEMU discard=ignore): vhost-blk sends every discard to the backend.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team



More information about the Devel mailing list