qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/1] Block patches
@ 2021-03-15  9:51 Stefan Hajnoczi
  2021-03-15  9:51 ` [PULL 1/1] virtio-blk: Respect discard granularity Stefan Hajnoczi
  2021-03-15 22:01 ` [PULL 0/1] Block patches Peter Maydell
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2021-03-15  9:51 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell
  Cc: Kevin Wolf, Eduardo Habkost, qemu-block, Michael S. Tsirkin,
	Max Reitz, Stefan Hajnoczi

The following changes since commit 6157b0e19721aadb4c7fdcfe57b2924af6144b14:

  Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-6.0-pull-=
request' into staging (2021-03-14 17:47:49 +0000)

are available in the Git repository at:

  https://gitlab.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to fb0b154c801e3447e505de420195fb7038695941:

  virtio-blk: Respect discard granularity (2021-03-15 09:48:53 +0000)

----------------------------------------------------------------
Pull request

----------------------------------------------------------------

Akihiko Odaki (1):
  virtio-blk: Respect discard granularity

 include/hw/virtio/virtio-blk.h | 1 +
 hw/block/virtio-blk.c          | 8 +++++++-
 hw/core/machine.c              | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

--=20
2.29.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PULL 1/1] virtio-blk: Respect discard granularity
  2021-03-15  9:51 [PULL 0/1] Block patches Stefan Hajnoczi
@ 2021-03-15  9:51 ` Stefan Hajnoczi
  2021-03-15 22:01 ` [PULL 0/1] Block patches Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2021-03-15  9:51 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell
  Cc: Kevin Wolf, Akihiko Odaki, Eduardo Habkost, qemu-block,
	Michael S. Tsirkin, Max Reitz, Stefan Hajnoczi,
	Stefano Garzarella

From: Akihiko Odaki <akihiko.odaki@gmail.com>

Report the configured granularity for discard operation to the
guest. If this is not set use the block size.

Since until now we have ignored the configured discard granularity
and always reported the block size, let's add
'report-discard-granularity' property and disable it for older
machine types to avoid migration issues.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20210225001239.47046-1-akihiko.odaki@gmail.com>
---
 include/hw/virtio/virtio-blk.h | 1 +
 hw/block/virtio-blk.c          | 8 +++++++-
 hw/core/machine.c              | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index 214ab74822..29655a406d 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -41,6 +41,7 @@ struct VirtIOBlkConf
     uint16_t num_queues;
     uint16_t queue_size;
     bool seg_max_adjust;
+    bool report_discard_granularity;
     uint32_t max_discard_sectors;
     uint32_t max_write_zeroes_sectors;
     bool x_enable_wce_if_config_wce;
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 3d2072cf75..d28979efb8 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -962,10 +962,14 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     blkcfg.wce = blk_enable_write_cache(s->blk);
     virtio_stw_p(vdev, &blkcfg.num_queues, s->conf.num_queues);
     if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD)) {
+        uint32_t discard_granularity = conf->discard_granularity;
+        if (discard_granularity == -1 || !s->conf.report_discard_granularity) {
+            discard_granularity = blk_size;
+        }
         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);
+                     discard_granularity >> BDRV_SECTOR_BITS);
         /*
          * We support only one segment per request since multiple segments
          * are not widely used and there are no userspace APIs that allow
@@ -1299,6 +1303,8 @@ static Property virtio_blk_properties[] = {
                      IOThread *),
     DEFINE_PROP_BIT64("discard", VirtIOBlock, host_features,
                       VIRTIO_BLK_F_DISCARD, true),
+    DEFINE_PROP_BOOL("report-discard-granularity", VirtIOBlock,
+                     conf.report_discard_granularity, true),
     DEFINE_PROP_BIT64("write-zeroes", VirtIOBlock, host_features,
                       VIRTIO_BLK_F_WRITE_ZEROES, true),
     DEFINE_PROP_UINT32("max-discard-sectors", VirtIOBlock,
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 4386f57b5c..4c1a4a4c32 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -39,6 +39,7 @@
 GlobalProperty hw_compat_5_2[] = {
     { "ICH9-LPC", "smm-compat", "on"},
     { "PIIX4_PM", "smm-compat", "on"},
+    { "virtio-blk-device", "report-discard-granularity", "off" },
 };
 const size_t hw_compat_5_2_len = G_N_ELEMENTS(hw_compat_5_2);
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PULL 0/1] Block patches
  2021-03-15  9:51 [PULL 0/1] Block patches Stefan Hajnoczi
  2021-03-15  9:51 ` [PULL 1/1] virtio-blk: Respect discard granularity Stefan Hajnoczi
@ 2021-03-15 22:01 ` Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2021-03-15 22:01 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Eduardo Habkost, Qemu-block, Michael S. Tsirkin,
	QEMU Developers, Max Reitz

On Mon, 15 Mar 2021 at 09:51, Stefan Hajnoczi <stefanha@redhat.com> wrote:
>
> The following changes since commit 6157b0e19721aadb4c7fdcfe57b2924af6144b14:
>
>   Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-6.0-pull-=
> request' into staging (2021-03-14 17:47:49 +0000)
>
> are available in the Git repository at:
>
>   https://gitlab.com/stefanha/qemu.git tags/block-pull-request
>
> for you to fetch changes up to fb0b154c801e3447e505de420195fb7038695941:
>
>   virtio-blk: Respect discard granularity (2021-03-15 09:48:53 +0000)
>
> ----------------------------------------------------------------
> Pull request
>
> ----------------------------------------------------------------
>


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/6.0
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-15 22:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-15  9:51 [PULL 0/1] Block patches Stefan Hajnoczi
2021-03-15  9:51 ` [PULL 1/1] virtio-blk: Respect discard granularity Stefan Hajnoczi
2021-03-15 22:01 ` [PULL 0/1] Block patches Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).