All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] xen-block: only advertize discard to the frontend when it is enabled...
       [not found] <20190320142825.24565-1-paul.durrant@citrix.com>
@ 2019-03-21 11:41 ` Anthony PERARD
       [not found] ` <20190321114157.GO11621@perard.uk.xensource.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Anthony PERARD @ 2019-03-21 11:41 UTC (permalink / raw)
  To: Paul Durrant
  Cc: Kevin Wolf, Stefano Stabellini, qemu-block, qemu-devel,
	Max Reitz, xen-devel

On Wed, Mar 20, 2019 at 02:28:25PM +0000, Paul Durrant wrote:
> ...and properly enable it when synthesizing a drive.
> 
> The Xen toolstack sets 'discard-enable' to '1' in xenstore when it wants
> to enable discard on a specified image. The code in
> xen_block_driver_create() correctly parses this and uses it to set

typo: It's xen_block_drive_create (s/driver/drive/), otherwise my IDE
can't find it :-(.

> 'discard' to 'unamp' for the file_layer, but fails to do the same for the

Looks like s/unamp/unmap/

> driver_layer (which effectively disables it). Meanwhile the code in
> xen_block_realize() advertizes discard support to the frontend in the
> default case (because conf->discard_granularity defaults to -1), even when

That doesn't match the code I'm reading, before the patch apply.
    if (discard_granularity > 0) feature-discard=1
Nothing seems to set discard_granularity, so it keeps it's default to
-1, so .... wait, discard_granularity is unsigned :-(

The description is fine then.

> the underlying image may not handle it.
> 
> This patch adds the missing option to the driver_layer in
> xen_block_driver_create() and checks whether BDRV_O_UNMAP is actually
> set on the block device before advertizing discard to the frontend.
> In the case that discard is supported it also makes sure that the
> granularity is set to the physical block size.
> 
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>

With the two typos fixed (which I can try to remember to do on commit):
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>

Thanks,

-- 
Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH] xen-block: only advertize discard to the frontend when it is enabled...
       [not found] ` <20190321114157.GO11621@perard.uk.xensource.com>
@ 2019-03-21 12:08   ` Paul Durrant
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Durrant @ 2019-03-21 12:08 UTC (permalink / raw)
  To: Anthony Perard
  Cc: Kevin Wolf, Stefano Stabellini, qemu-block, qemu-devel,
	Max Reitz, xen-devel

> -----Original Message-----
> From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> Sent: 21 March 2019 11:42
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: xen-devel@lists.xenproject.org; qemu-block@nongnu.org; qemu-devel@nongnu.org; Stefano Stabellini
> <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>; Max Reitz <mreitz@redhat.com>
> Subject: Re: [PATCH] xen-block: only advertize discard to the frontend when it is enabled...
> 
> On Wed, Mar 20, 2019 at 02:28:25PM +0000, Paul Durrant wrote:
> > ...and properly enable it when synthesizing a drive.
> >
> > The Xen toolstack sets 'discard-enable' to '1' in xenstore when it wants
> > to enable discard on a specified image. The code in
> > xen_block_driver_create() correctly parses this and uses it to set
> 
> typo: It's xen_block_drive_create (s/driver/drive/), otherwise my IDE
> can't find it :-(.

Sorry, my fingers are so used to typing 'driver'

> 
> > 'discard' to 'unamp' for the file_layer, but fails to do the same for the
> 
> Looks like s/unamp/unmap/

Yes.

> 
> > driver_layer (which effectively disables it). Meanwhile the code in
> > xen_block_realize() advertizes discard support to the frontend in the
> > default case (because conf->discard_granularity defaults to -1), even when
> 
> That doesn't match the code I'm reading, before the patch apply.
>     if (discard_granularity > 0) feature-discard=1
> Nothing seems to set discard_granularity, so it keeps it's default to
> -1, so .... wait, discard_granularity is unsigned :-(
> 
> The description is fine then.

Indeed.

> 
> > the underlying image may not handle it.
> >
> > This patch adds the missing option to the driver_layer in
> > xen_block_driver_create() and checks whether BDRV_O_UNMAP is actually
> > set on the block device before advertizing discard to the frontend.
> > In the case that discard is supported it also makes sure that the
> > granularity is set to the physical block size.
> >
> > Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
> 
> With the two typos fixed (which I can try to remember to do on commit):
> Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>

Ok, thanks.

  Paul

> 
> Thanks,
> 
> --
> Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* [PATCH] xen-block: only advertize discard to the frontend when it is enabled...
@ 2019-03-20 14:28 Paul Durrant
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Durrant @ 2019-03-20 14:28 UTC (permalink / raw)
  To: xen-devel, qemu-block, qemu-devel
  Cc: Anthony Perard, Kevin Wolf, Paul Durrant, Stefano Stabellini, Max Reitz

...and properly enable it when synthesizing a drive.

The Xen toolstack sets 'discard-enable' to '1' in xenstore when it wants
to enable discard on a specified image. The code in
xen_block_driver_create() correctly parses this and uses it to set
'discard' to 'unamp' for the file_layer, but fails to do the same for the
driver_layer (which effectively disables it). Meanwhile the code in
xen_block_realize() advertizes discard support to the frontend in the
default case (because conf->discard_granularity defaults to -1), even when
the underlying image may not handle it.

This patch adds the missing option to the driver_layer in
xen_block_driver_create() and checks whether BDRV_O_UNMAP is actually
set on the block device before advertizing discard to the frontend.
In the case that discard is supported it also makes sure that the
granularity is set to the physical block size.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Max Reitz <mreitz@redhat.com>
---
 hw/block/xen-block.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index 70fc2455e8..a848849f48 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -232,8 +232,14 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
     blk_set_dev_ops(conf->blk, &xen_block_dev_ops, blockdev);
     blk_set_guest_block_size(conf->blk, conf->logical_block_size);
 
-    if (conf->discard_granularity > 0) {
+    if (conf->discard_granularity == -1) {
+        conf->discard_granularity = conf->physical_block_size;
+    }
+
+    if (blk_get_flags(conf->blk) & BDRV_O_UNMAP) {
         xen_device_backend_printf(xendev, "feature-discard", "%u", 1);
+        xen_device_backend_printf(xendev, "discard-granularity", "%u",
+                                  conf->discard_granularity);
     }
 
     xen_device_backend_printf(xendev, "feature-flush-cache", "%u", 1);
@@ -755,6 +761,7 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
     drive->id = g_strdup(id);
 
     file_layer = qdict_new();
+    driver_layer = qdict_new();
 
     qdict_put_str(file_layer, "driver", "file");
     qdict_put_str(file_layer, "filename", filename);
@@ -782,6 +789,7 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
 
         if (!qemu_strtoul(discard_enable, NULL, 2, &value) && !!value) {
             qdict_put_str(file_layer, "discard", "unmap");
+            qdict_put_str(driver_layer, "discard", "unmap");
         }
     }
 
@@ -791,8 +799,6 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
      */
     qdict_put_str(file_layer, "locking", "off");
 
-    driver_layer = qdict_new();
-
     qdict_put_str(driver_layer, "driver", driver);
     g_free(driver);
 
-- 
2.20.1.2.gb21ebb6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

end of thread, other threads:[~2019-03-21 12:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190320142825.24565-1-paul.durrant@citrix.com>
2019-03-21 11:41 ` [PATCH] xen-block: only advertize discard to the frontend when it is enabled Anthony PERARD
     [not found] ` <20190321114157.GO11621@perard.uk.xensource.com>
2019-03-21 12:08   ` Paul Durrant
2019-03-20 14:28 Paul Durrant

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.