All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>,
	andrey.zhadchenko@virtuozzo.com
Cc: svt-core@virtuozzo.com
Subject: Re: [PATCH hci-8.2 v2 2/2] vhost-blk: advertise discard on a backend that supports it
Date: Thu, 26 Nov 2026 14:47:09 +0200	[thread overview]
Message-ID: <5de1b498-dcb3-4ded-95b8-dee5a5025594@virtuozzo.com> (raw)
In-Reply-To: <20261126093912.891440-3-alexander.ivanov@virtuozzo.com>

On 11/26/26 11:39 AM, Alexander Ivanov wrote:
> vhost-blk in the kernel now handles VIRTIO_BLK_T_DISCARD, but with the
> discard property on, the config space reports zero for max_discard_seg,
> max_discard_sectors and discard_sector_alignment. A Linux guest reads a
> zero max_discard_seg as seg_max and merges adjacent discards into one
> multi-segment request, which the kernel rejects with
> VIRTIO_BLK_S_UNSUPP.
> 
> Handle discard the way write zeroes is handled. Read discard_max_bytes
> of a writable backend from sysfs once at startup and use it only to
> tell whether the backend supports discard. The kernel sends a discard
> as one bio, which the block layer splits by the backend limit, so it
> bounds the range only by the size of one bio, as it does for write
> zeroes. Advertise the constant write zeroes uses, renamed to
> VHOST_BLK_MAX_RANGE_SECTORS, one segment per request, as virtio-blk
> does, and the logical block size as the alignment. Do not offer
> VIRTIO_BLK_F_DISCARD when the backend reports no limit, the limit
> cannot be read, or the backend is opened read-only: the kernel fails a
> discard on a read-only backend with VIRTIO_BLK_S_IOERR.
> 
> The property stays off by default. A kernel without discard support in
> vhost-blk does not offer the feature, so it is not negotiated there.
> Warn about that at realize: a migration to such a node otherwise fails
> only in virtio_load() with a generic "Features ... unsupported".
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-141683
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>  hw/block/vhost-blk.c          | 32 ++++++++++++++++++++++++++++++--
>  include/hw/virtio/vhost-blk.h |  3 ++-
>  2 files changed, 32 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index 96878de5bb4..c7db99c57e1 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c
> @@ -672,6 +672,20 @@ static bool vhost_blk_open_backend(VHostBlk *s, Error **errp)
>                              s->conf.devpath);
>              }
>          }
> +
> +        if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD)) {
> +            Error *local_err = NULL;
> +
> +            if (!vhost_blk_read_queue_attr(s->backend_rdev,
> +                                           "discard_max_bytes",
> +                                           &s->discard, &local_err)) {
> +                warn_reportf_err(local_err, "vhost-blk: unable to read discard "
> +                                 "limit of '%s': ", s->conf.devpath);
> +            } else if (!s->discard) {
> +                warn_report("vhost-blk: '%s' does not support discard",
> +                            s->conf.devpath);
> +            }
> +        }
>      }
>  
>      vhost_blk_update_size(s, errp);
> @@ -769,6 +783,11 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
>          goto cleanup;
>      }
>  
> +    if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD) &&
> +        !virtio_has_feature(s->dev.features, VIRTIO_BLK_F_DISCARD)) {
> +        warn_report("vhost-blk: kernel does not support discard");
> +    }
I'm wondering why this warning takes place for discard but not
write_zeroes.  Is that an omission?

Andrey

  reply	other threads:[~2026-11-26 12:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:39 [PATCH hci-8.2 v2 0/2] vhost-blk: support discard Alexander Ivanov
2026-11-26  9:39 ` [PATCH hci-8.2 v2 1/2] vhost-blk: read any queue attribute of the backend from sysfs Alexander Ivanov
2026-11-26 12:47   ` Andrey Drobyshev
2026-11-26  9:39 ` [PATCH hci-8.2 v2 2/2] vhost-blk: advertise discard on a backend that supports it Alexander Ivanov
2026-11-26 12:47   ` Andrey Drobyshev [this message]
2026-11-26 16:08     ` Alexander Ivanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5de1b498-dcb3-4ded-95b8-dee5a5025594@virtuozzo.com \
    --to=andrey.drobyshev@virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.