xen-block: changes for discard support
Subsystems (3)
cover xen-block: changes for discard support
Fix blkfront to handle all sorts of backends.
Also let blkback recognize a xenstore property to disable discard for a given device. It requires upcoming libxl changes ("discard-enable"):
http://lists.xenproject.org/archives/html/xen-devel/2014-01/msg02632.html
Olaf Hering (3):
xen-blkfront: remove type check from blkfront_setup_discard xen blkif.h: fix comment typo in discard-alignment xen/blkback: disable discard feature if requested by toolstack
drivers/block/xen-blkback/xenbus.c | 7 ++++++- drivers/block/xen-blkfront.c | 40 +++++++++++++------------------------- include/xen/interface/io/blkif.h | 2 +- 3 files changed, 21 insertions(+), 28 deletions(-)
PATCH 1/3 xen-blkfront: remove type check from blkfront_setup_discard
In its initial implementation a check for "type" was added, but only phy and file are handled. This breaks advertised discard support for other type values such as qdisk.
Fix and simplify this function: If the backend advertises discard support it is supposed to implement it properly, so enable feature_discard unconditionally. If the backend advertises the need for a certain granularity and alignment then propagate both properties to the blocklayer. The discard-secure property is a boolean, update the code to reflect that.
--- drivers/block/xen-blkfront.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-)
drivers/block/xen-blkfront.c +14 -26
@@ -1635,36 +1635,24 @@ blkfront_closing(struct blkfront_info *info)static void blkfront_setup_discard (struct blkfront_info *info) {int err; -char *type;unsigned int discard_granularity;unsigned int discard_alignment;unsigned int discard_secure; - type =xenbus_read (XBT_NIL , info->xbdev->otherend,"type" ,NULL ); -if (IS_ERR (type)) -return ; - - info->feature_secdiscard =0 ; -if (strncmp (type,"phy" ,3 ) ==0 ) { - err =xenbus_gather (XBT_NIL , info->xbdev->otherend, -"discard-granularity" ,"%u" , &discard_granularity, -"discard-alignment" ,"%u" , &discard_alignment, -NULL ); -if (!err) { - info->feature_discard =1 ; - info->discard_granularity = discard_granularity; - info->discard_alignment = discard_alignment; - } - err =xenbus_gather (XBT_NIL , info->xbdev->otherend, -"discard-secure" ,"%d" , &discard_secure, -NULL ); -if (!err) - info->feature_secdiscard = discard_secure; - - }else if (strncmp (type,"file" ,4 ) ==0 ) - info->feature_discard =1 ; - -kfree (type); + info->feature_discard =1 ; + err =xenbus_gather (XBT_NIL , info->xbdev->otherend, +"discard-granularity" ,"%u" , &discard_granularity, +"discard-alignment" ,"%u" , &discard_alignment, +NULL ); +if (!err) { + info->discard_granularity = discard_granularity; + info->discard_alignment = discard_alignment; + } + err =xenbus_gather (XBT_NIL , info->xbdev->otherend, +"discard-secure" ,"%d" , &discard_secure, +NULL ); +if (!err) + info->feature_secdiscard = !!discard_secure; }static int blkfront_setup_indirect (struct blkfront_info *info)
PATCH 1/3 xen-blkfront: remove type check from blkfront_setup_discard
In reply to Olaf HeringIn its initial implementation a check for "type" was added, but only phy and file are handled. This breaks advertised discard support for other type values such as qdisk.
Fix and simplify this function: If the backend advertises discard support it is supposed to implement it properly, so enable feature_discard unconditionally. If the backend advertises the need for a certain granularity and alignment then propagate both properties to the blocklayer. The discard-secure property is a boolean, update the code to reflect that.
--- drivers/block/xen-blkfront.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-)
drivers/block/xen-blkfront.c +14 -26
@@ -1635,36 +1635,24 @@ blkfront_closing(struct blkfront_info *info)static void blkfront_setup_discard (struct blkfront_info *info) {int err; -char *type;unsigned int discard_granularity;unsigned int discard_alignment;unsigned int discard_secure; - type =xenbus_read (XBT_NIL , info->xbdev->otherend,"type" ,NULL ); -if (IS_ERR (type)) -return ; - - info->feature_secdiscard =0 ; -if (strncmp (type,"phy" ,3 ) ==0 ) { - err =xenbus_gather (XBT_NIL , info->xbdev->otherend, -"discard-granularity" ,"%u" , &discard_granularity, -"discard-alignment" ,"%u" , &discard_alignment, -NULL ); -if (!err) { - info->feature_discard =1 ; - info->discard_granularity = discard_granularity; - info->discard_alignment = discard_alignment; - } - err =xenbus_gather (XBT_NIL , info->xbdev->otherend, -"discard-secure" ,"%d" , &discard_secure, -NULL ); -if (!err) - info->feature_secdiscard = discard_secure; - - }else if (strncmp (type,"file" ,4 ) ==0 ) - info->feature_discard =1 ; - -kfree (type); + info->feature_discard =1 ; + err =xenbus_gather (XBT_NIL , info->xbdev->otherend, +"discard-granularity" ,"%u" , &discard_granularity, +"discard-alignment" ,"%u" , &discard_alignment, +NULL ); +if (!err) { + info->discard_granularity = discard_granularity; + info->discard_alignment = discard_alignment; + } + err =xenbus_gather (XBT_NIL , info->xbdev->otherend, +"discard-secure" ,"%d" , &discard_secure, +NULL ); +if (!err) + info->feature_secdiscard = !!discard_secure; }static int blkfront_setup_indirect (struct blkfront_info *info)
PATCH 2/3 xen blkif.h: fix comment typo in discard-alignment
In reply to Olaf HeringAdd the missing 'n' to discard-alignment
--- include/xen/interface/io/blkif.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/xen/interface/io/blkif.h +1 -1
@@ -86,7 +86,7 @@ typedef uint64_t blkif_sector_t;* Interface%20manuals/100293068c.pdf * The backend can optionally provide three extra XenBus attributes to * further optimize the discard functionality: -* 'discard-aligment' - Devices that support discard functionality may +* 'discard-alignment' - Devices that support discard functionality may * internally allocate space in units that are bigger than the exported * logical block size. The discard-alignment parameter indicates how many bytes * the beginning of the partition is offset from the internal allocation unit's
PATCH 2/3 xen blkif.h: fix comment typo in discard-alignment
In reply to Olaf HeringAdd the missing 'n' to discard-alignment
--- include/xen/interface/io/blkif.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/xen/interface/io/blkif.h +1 -1
@@ -86,7 +86,7 @@ typedef uint64_t blkif_sector_t;* Interface%20manuals/100293068c.pdf * The backend can optionally provide three extra XenBus attributes to * further optimize the discard functionality: -* 'discard-aligment' - Devices that support discard functionality may +* 'discard-alignment' - Devices that support discard functionality may * internally allocate space in units that are bigger than the exported * logical block size. The discard-alignment parameter indicates how many bytes * the beginning of the partition is offset from the internal allocation unit's
PATCH 3/3 xen/blkback: disable discard feature if requested by toolstack
In reply to Olaf HeringNewer toolstacks may provide a boolean property "discard-enable" in the backend node. Its purpose is to disable discard for file backed storage to avoid fragmentation. Recognize this setting also for physical storage. If that property exists and is false, do not advertise "feature-discard" to the frontend.
--- drivers/block/xen-blkback/xenbus.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/block/xen-blkback/xenbus.c +6 -1
@@ -467,10 +467,15 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_infostruct xenbus_device *dev = be->dev;struct xen_blkif *blkif = be->blkif;int err; -int state =0 ; +int state =0 , discard_enable;struct block_device *bdev = be->blkif->vbd.bdev;struct request_queue *q =bdev_get_queue (bdev); + err =xenbus_scanf (XBT_NIL , dev->nodename,"discard-enable" ,"%d" , + &discard_enable); +if (err ==1 && !discard_enable) +return ; +if (blk_queue_discard (q)) { err = xenbus_printf(xbt, dev->nodename, "discard-granularity", "%u",
PATCH 3/3 xen/blkback: disable discard feature if requested by toolstack
In reply to Olaf HeringNewer toolstacks may provide a boolean property "discard-enable" in the backend node. Its purpose is to disable discard for file backed storage to avoid fragmentation. Recognize this setting also for physical storage. If that property exists and is false, do not advertise "feature-discard" to the frontend.
--- drivers/block/xen-blkback/xenbus.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/block/xen-blkback/xenbus.c +6 -1
@@ -467,10 +467,15 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_infostruct xenbus_device *dev = be->dev;struct xen_blkif *blkif = be->blkif;int err; -int state =0 ; +int state =0 , discard_enable;struct block_device *bdev = be->blkif->vbd.bdev;struct request_queue *q =bdev_get_queue (bdev); + err =xenbus_scanf (XBT_NIL , dev->nodename,"discard-enable" ,"%d" , + &discard_enable); +if (err ==1 && !discard_enable) +return ; +if (blk_queue_discard (q)) { err = xenbus_printf(xbt, dev->nodename, "discard-granularity", "%u",