From 417e6b70d73ffe8f8d3938aa30a413b35098e614 Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Mon, 19 May 2014 11:50:19 +0200 Subject: [PATCH] libxl: add option for discard support to xl disk configuration Handle new boolean option discard/no-discard for disk configuration. It is supposed to disable discard support if file based backing storage was intentionally created non-sparse to avoid fragmentation of the file. The option intended for the backend driver. A new boolean property "discard-enable" is written to the backend node. An upcoming patch for qemu will make use of this property. The kernel blkback driver may be updated as well to disable discard for phy based backing storage. Signed-off-by: Olaf Hering Acked-by: Ian Jackson Cc: Stefano Stabellini Cc: Ian Campbell --- docs/misc/xl-disk-configuration.txt | 17 ++++++ tools/libxl/check-xl-disk-parse | 80 ++++++++++++++++++++++++++--- tools/libxl/libxl.c | 3 ++ tools/libxl/libxl.h | 5 ++ tools/libxl/libxl_types.idl | 1 + tools/libxl/libxlu_disk.c | 1 + tools/libxl/libxlu_disk_l.l | 2 + xen/include/public/io/blkif.h | 10 ++++ 8 files changed, 112 insertions(+), 7 deletions(-) diff --git a/docs/misc/xl-disk-configuration.txt b/docs/misc/xl-disk-configuration.txt index 11fee9a9b8..6a2118dfc4 100644 --- a/docs/misc/xl-disk-configuration.txt +++ b/docs/misc/xl-disk-configuration.txt @@ -217,6 +217,23 @@ If in the future the bug is fixed properly this option will then be silently ignored. +discard / no-discard +--------------- + +Description: Request that backend advertise discard support to frontend +Supported values: discard + no-discard +Mandatory: No +Default value: discard + +An advisory setting for the backend driver, specifying whether to +advertise discard support (TRIM, UNMAP) to the frontend. The real +benefit of this option is to be able to force it off rather than on. It +can be used to disable "hole punching" for file based backends which +were intentionally created non-sparse to avoid fragmentation of the +file. + + ============================================ DEPRECATED PARAMETERS, PREFIXES AND SYNTAXES ============================================ diff --git a/tools/libxl/check-xl-disk-parse b/tools/libxl/check-xl-disk-parse index 0698586cf2..1bec4ca9df 100755 --- a/tools/libxl/check-xl-disk-parse +++ b/tools/libxl/check-xl-disk-parse @@ -62,7 +62,8 @@ disk: { "removable": 0, "readwrite": 1, "is_cdrom": 0, - "direct_io_safe": false + "direct_io_safe": false, + "discard_enable": "True" } END @@ -84,7 +85,8 @@ disk: { "removable": 1, "readwrite": 0, "is_cdrom": 1, - "direct_io_safe": false + "direct_io_safe": false, + "discard_enable": "False" } END @@ -107,7 +109,8 @@ disk: { "removable": 0, "readwrite": 1, "is_cdrom": 0, - "direct_io_safe": false + "direct_io_safe": false, + "discard_enable": "True" } EOF @@ -125,7 +128,8 @@ disk: { "removable": 1, "readwrite": 0, "is_cdrom": 1, - "direct_io_safe": false + "direct_io_safe": false, + "discard_enable": "False" } EOF @@ -147,7 +151,8 @@ disk: { "removable": 1, "readwrite": 0, "is_cdrom": 1, - "direct_io_safe": false + "direct_io_safe": false, + "discard_enable": "False" } EOF @@ -166,7 +171,8 @@ disk: { "removable": 0, "readwrite": 1, "is_cdrom": 0, - "direct_io_safe": false + "direct_io_safe": false, + "discard_enable": "True" } EOF @@ -187,7 +193,8 @@ disk: { "removable": 0, "readwrite": 1, "is_cdrom": 0, - "direct_io_safe": false + "direct_io_safe": false, + "discard_enable": "True" } EOF @@ -196,4 +203,63 @@ EOF # http://www.drbd.org/users-guide-emb/s-xen-configure-domu.html one 0 drbd:app01,hda,w +expected <discard_enable) ? + "1" : "0"); flexarray_append(front, "backend-id"); flexarray_append(front, libxl__sprintf(gc, "%d", disk->backend_domid)); diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 84f9c0eea8..c7aa817762 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -101,6 +101,11 @@ */ #define LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE 1 +/* + * The libxl_device_disk has the discard_enable field. + */ +#define LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE 1 + /* * libxl ABI compatibility * diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 8944686b8a..52f1aa9f21 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -417,6 +417,7 @@ libxl_device_disk = Struct("device_disk", [ ("readwrite", integer), ("is_cdrom", integer), ("direct_io_safe", bool), + ("discard_enable", libxl_defbool), ]) libxl_device_nic = Struct("device_nic", [ diff --git a/tools/libxl/libxlu_disk.c b/tools/libxl/libxlu_disk.c index 18fe386dbe..752a2c7cdc 100644 --- a/tools/libxl/libxlu_disk.c +++ b/tools/libxl/libxlu_disk.c @@ -79,6 +79,7 @@ int xlu_disk_parse(XLU_Config *cfg, if (!disk->pdev_path || !strcmp(disk->pdev_path, "")) disk->format = LIBXL_DISK_FORMAT_EMPTY; } + libxl_defbool_setdefault(&disk->discard_enable, !!disk->readwrite); if (!disk->vdev) { xlu__disk_err(&dpc,0, "no vdev specified"); diff --git a/tools/libxl/libxlu_disk_l.l b/tools/libxl/libxlu_disk_l.l index ba8577cc0c..1a5deb5be6 100644 --- a/tools/libxl/libxlu_disk_l.l +++ b/tools/libxl/libxlu_disk_l.l @@ -174,6 +174,8 @@ backendtype=[^,]*,? { STRIP(','); setbackendtype(DPC,FROMEQUALS); } vdev=[^,]*,? { STRIP(','); SAVESTRING("vdev", vdev, FROMEQUALS); } script=[^,]*,? { STRIP(','); SAVESTRING("script", script, FROMEQUALS); } direct-io-safe,? { DPC->disk->direct_io_safe = 1; } +discard,? { libxl_defbool_set(&DPC->disk->discard_enable, true); } +no-discard,? { libxl_defbool_set(&DPC->disk->discard_enable, false); } /* the target magic parameter, eats the rest of the string */ diff --git a/xen/include/public/io/blkif.h b/xen/include/public/io/blkif.h index 1e7cea948e..6baf7fb519 100644 --- a/xen/include/public/io/blkif.h +++ b/xen/include/public/io/blkif.h @@ -197,6 +197,16 @@ * *------------------------- Backend Device Properties ------------------------- * + * discard-enable + * Values: 0/1 (boolean) + * Default Value: 1 + * + * This optional property, set by the toolstack, instructs the backend + * to offer discard to the frontend. If the property is missing the + * backend should offer discard if the backing storage actually supports + * it. This optional property, set by the toolstack, requests that the + * backend offer, or not offer, discard to the frontend. + * * discard-alignment * Values: * Default Value: 0 -- 2.39.5