[Devel] [PATCH hci-8.2 v4 0/4] drivers/vhost/blk: fix write zeroes errors, support VIRTIO_BLK_F_DISCARD

Alexander Ivanov alexander.ivanov at virtuozzo.com
Wed Nov 25 17:21:41 MSK 2026


vhost-blk does not offer VIRTIO_BLK_F_DISCARD, so a guest on vhost-blk
cannot release unused blocks of its disk, while virtio-blk in QEMU can.

vhost-blk also fails WRITE ZEROES with VIRTIO_BLK_S_IOERR when the range
is above the backend limit, which the guest does not know, and once the
backend loses WRITE ZEROES support, e.g. on a dm table reload. In the
latter case the guest gets -EIO instead of falling back to writing
zeroes itself.

Patch 1 drops the ring features that are already part of VHOST_FEATURES.
Patch 2 stops checking WRITE ZEROES ranges against the backend limit.
Patch 3 answers VIRTIO_BLK_S_UNSUPP to WRITE ZEROES when the backend has
no WRITE ZEROES support. Patch 4 handles VIRTIO_BLK_T_DISCARD as a
single-segment request sent to the backend as one REQ_OP_DISCARD bio.

The QEMU side is sent separately.

v4:
- patch 2: say a backend without WRITE ZEROES still gets
  VIRTIO_BLK_S_IOERR and the VMM still has to cap
  max_write_zeroes_sectors
- patch 3: look up the backend bdev in vhost_blk_req_done() only when
  the bio failed
- patch 4: pass the backend file to vhost_blk_parse_segment() instead of
  bdev; test for REQ_OP_DISCARD instead of op_is_discard(); say the VMM
  rounds the limit down to the logical block size and must not offer
  discard for a drive with discard=ignore

v3:
- merge with "drivers/vhost/blk: return UNSUPP for write zeroes on a
  backend without it", split into patches 2 and 3 and put before the
  discard patch, so the WRITE ZEROES fixes apply without it
- patch 3: test the op in vhost_blk_req_done() through req->bi_opf;
  treat any failure as unsupported once the backend limit is 0; say this
  replaces the contract of 3b2e28a4f6b7 and add its Fixes: line
- patch 4: count any discard failure as success once the backend
  discard limit is 0; pass bdev to vhost_blk_parse_segment() instead of
  a size limit; complete both request types through
  vhost_blk_req_submit_or_complete(); say which limits the VMM must set

v2:
- discard patch: keep vhost_blk_parse_write_zeroes() and add
  vhost_blk_parse_discard(), both on top of vhost_blk_parse_segment()
  that reads and checks the segment, instead of one parser full of
  per-type conditions

https://virtuozzo.atlassian.net/browse/VSTOR-141683
https://virtuozzo.atlassian.net/browse/VSTOR-141684

Assisted-by: LLM

Alexander Ivanov (4):
  drivers/vhost/blk: drop ring features already in VHOST_FEATURES
  drivers/vhost/blk: stop failing write zeroes above the backend limit
  drivers/vhost/blk: return UNSUPP for write zeroes on a backend without
    it
  drivers/vhost/blk: support VIRTIO_BLK_F_DISCARD

 drivers/vhost/blk.c | 115 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 88 insertions(+), 27 deletions(-)

-- 
2.53.0



More information about the Devel mailing list