All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Akihiko Odaki <akihiko.odaki@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH] virtio-blk: Respect discard granularity
Date: Mon, 22 Feb 2021 16:49:00 +0000	[thread overview]
Message-ID: <YDPgfPiXQ9fNmGlq@stefanha-x1.localdomain> (raw)
In-Reply-To: <20210219101919.91069-1-akihiko.odaki@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1797 bytes --]

On Fri, Feb 19, 2021 at 07:19:19PM +0900, Akihiko Odaki wrote:
> Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
> ---
>  hw/block/virtio-blk.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index bac2d6fa2b2..692fd17b0e0 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -965,7 +965,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
>          virtio_stl_p(vdev, &blkcfg.max_discard_sectors,
>                       s->conf.max_discard_sectors);
>          virtio_stl_p(vdev, &blkcfg.discard_sector_alignment,
> -                     blk_size >> BDRV_SECTOR_BITS);
> +                     conf->discard_granularity >> BDRV_SECTOR_BITS);

Please handle the -1 default value like this:

  uint32_t discard_granularity = conf->discard_granularity;
  if (conf->discard_granularity == -1) {
      discard_granularity = BDRV_SECTOR_SIZE;
  }

I noticed this when comparing the blk_size and discard_granularity
values when I run QEMU:

  $ qemu-system-x86_64 -M accel=kvm -m 1G -cpu host -drive if=virtio,file=test.img,format=raw
  blk_size 512
  discard_granularity 4294967295

Also, please add a compat prop in hw/core/machine.c to ensure that
existing machine types are unaffected by this change. This can be done
by adding DEFINE_PROP_BOOL("report-discard-granularity", ...) in
hw/block/virtio-blk.c and then setting it to false for existing machine
types in hw/core/machine.c. Then new machine types benefit from the new
feature but existing machine types will be unchanged (eliminating the
risk of live migration/snapshot incompatibilities when the device
unexpectedly changes behavior while the guest is running).

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2021-02-22 16:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-19 10:19 [PATCH] virtio-blk: Respect discard granularity Akihiko Odaki
2021-02-22 16:49 ` Stefan Hajnoczi [this message]
2021-02-23  5:36   ` [PATCH v2] " Akihiko Odaki
2021-02-23 11:24     ` Stefano Garzarella
2021-02-23 12:09       ` [PATCH v3] " Akihiko Odaki
2021-02-23 14:26         ` Michael S. Tsirkin
2021-02-24 10:17         ` Stefano Garzarella
2021-02-25  0:12           ` [PATCH v4] " Akihiko Odaki
2021-02-25  8:34             ` Stefano Garzarella
2021-03-08 16:52             ` Stefan Hajnoczi

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=YDPgfPiXQ9fNmGlq@stefanha-x1.localdomain \
    --to=stefanha@redhat.com \
    --cc=akihiko.odaki@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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.