xen-block: only advertize discard to the frontend when it is enabled...
commit15f084505a8556b70134e9081176e90a1c178b7b
authorPaul Durrant <paul.durrant@citrix.com>
Wed, 20 Mar 2019 14:28:25 +0000 (20 14:28 +0000)
committerAnthony PERARD <anthony.perard@citrix.com>
Thu, 4 Apr 2019 11:41:23 +0000 (4 12:41 +0100)
tree98140dbb134b524a4b9daa26273d7b45a9f23442
parentf4b37171378b0b1782570060c3411a504375d1bc
xen-block: only advertize discard to the frontend when it is enabled...

...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_drive_create() correctly parses this and uses it to set
'discard' to 'unmap' 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>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Message-Id: <20190320142825.24565-1-paul.durrant@citrix.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
hw/block/xen-block.c